# 1 "src/memwatch.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "src/memwatch.c"
# 110 "src/memwatch.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 28 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 335 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 360 "/usr/include/sys/cdefs.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 361 "/usr/include/sys/cdefs.h" 2 3 4
# 336 "/usr/include/features.h" 2 3 4
# 359 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4



# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 5 "/usr/include/gnu/stubs.h" 2 3 4


# 1 "/usr/include/gnu/stubs-32.h" 1 3 4
# 8 "/usr/include/gnu/stubs.h" 2 3 4
# 360 "/usr/include/features.h" 2 3 4
# 29 "/usr/include/stdio.h" 2 3 4





# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 214 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 3 4
typedef unsigned int size_t;
# 35 "/usr/include/stdio.h" 2 3 4

# 1 "/usr/include/bits/types.h" 1 3 4
# 28 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 29 "/usr/include/bits/types.h" 2 3 4


typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;


typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;




__extension__ typedef signed long long int __int64_t;
__extension__ typedef unsigned long long int __uint64_t;







__extension__ typedef long long int __quad_t;
__extension__ typedef unsigned long long int __u_quad_t;
# 131 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/typesizes.h" 1 3 4
# 132 "/usr/include/bits/types.h" 2 3 4


__extension__ typedef __u_quad_t __dev_t;
__extension__ typedef unsigned int __uid_t;
__extension__ typedef unsigned int __gid_t;
__extension__ typedef unsigned long int __ino_t;
__extension__ typedef __u_quad_t __ino64_t;
__extension__ typedef unsigned int __mode_t;
__extension__ typedef unsigned int __nlink_t;
__extension__ typedef long int __off_t;
__extension__ typedef __quad_t __off64_t;
__extension__ typedef int __pid_t;
__extension__ typedef struct { int __val[2]; } __fsid_t;
__extension__ typedef long int __clock_t;
__extension__ typedef unsigned long int __rlim_t;
__extension__ typedef __u_quad_t __rlim64_t;
__extension__ typedef unsigned int __id_t;
__extension__ typedef long int __time_t;
__extension__ typedef unsigned int __useconds_t;
__extension__ typedef long int __suseconds_t;

__extension__ typedef int __daddr_t;
__extension__ typedef long int __swblk_t;
__extension__ typedef int __key_t;


__extension__ typedef int __clockid_t;


__extension__ typedef void * __timer_t;


__extension__ typedef long int __blksize_t;




__extension__ typedef long int __blkcnt_t;
__extension__ typedef __quad_t __blkcnt64_t;


__extension__ typedef unsigned long int __fsblkcnt_t;
__extension__ typedef __u_quad_t __fsblkcnt64_t;


__extension__ typedef unsigned long int __fsfilcnt_t;
__extension__ typedef __u_quad_t __fsfilcnt64_t;

__extension__ typedef int __ssize_t;



typedef __off64_t __loff_t;
typedef __quad_t *__qaddr_t;
typedef char *__caddr_t;


__extension__ typedef int __intptr_t;


__extension__ typedef unsigned int __socklen_t;
# 37 "/usr/include/stdio.h" 2 3 4
# 45 "/usr/include/stdio.h" 3 4
struct _IO_FILE;



typedef struct _IO_FILE FILE;





# 65 "/usr/include/stdio.h" 3 4
typedef struct _IO_FILE __FILE;
# 75 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/libio.h" 1 3 4
# 32 "/usr/include/libio.h" 3 4
# 1 "/usr/include/_G_config.h" 1 3 4
# 15 "/usr/include/_G_config.h" 3 4
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 16 "/usr/include/_G_config.h" 2 3 4




# 1 "/usr/include/wchar.h" 1 3 4
# 78 "/usr/include/wchar.h" 3 4
typedef struct
{
  int __count;
  union
  {

    unsigned int __wch;



    char __wchb[4];
  } __value;
} __mbstate_t;
# 21 "/usr/include/_G_config.h" 2 3 4

typedef struct
{
  __off_t __pos;
  __mbstate_t __state;
} _G_fpos_t;
typedef struct
{
  __off64_t __pos;
  __mbstate_t __state;
} _G_fpos64_t;
# 53 "/usr/include/_G_config.h" 3 4
typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
# 33 "/usr/include/libio.h" 2 3 4
# 53 "/usr/include/libio.h" 3 4
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h" 1 3 4
# 43 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 54 "/usr/include/libio.h" 2 3 4
# 170 "/usr/include/libio.h" 3 4
struct _IO_jump_t; struct _IO_FILE;
# 180 "/usr/include/libio.h" 3 4
typedef void _IO_lock_t;





struct _IO_marker {
  struct _IO_marker *_next;
  struct _IO_FILE *_sbuf;



  int _pos;
# 203 "/usr/include/libio.h" 3 4
};


enum __codecvt_result
{
  __codecvt_ok,
  __codecvt_partial,
  __codecvt_error,
  __codecvt_noconv
};
# 271 "/usr/include/libio.h" 3 4
struct _IO_FILE {
  int _flags;




  char* _IO_read_ptr;
  char* _IO_read_end;
  char* _IO_read_base;
  char* _IO_write_base;
  char* _IO_write_ptr;
  char* _IO_write_end;
  char* _IO_buf_base;
  char* _IO_buf_end;

  char *_IO_save_base;
  char *_IO_backup_base;
  char *_IO_save_end;

  struct _IO_marker *_markers;

  struct _IO_FILE *_chain;

  int _fileno;



  int _flags2;

  __off_t _old_offset;



  unsigned short _cur_column;
  signed char _vtable_offset;
  char _shortbuf[1];



  _IO_lock_t *_lock;
# 319 "/usr/include/libio.h" 3 4
  __off64_t _offset;
# 328 "/usr/include/libio.h" 3 4
  void *__pad1;
  void *__pad2;
  void *__pad3;
  void *__pad4;
  size_t __pad5;

  int _mode;

  char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];

};


typedef struct _IO_FILE _IO_FILE;


struct _IO_FILE_plus;

extern struct _IO_FILE_plus _IO_2_1_stdin_;
extern struct _IO_FILE_plus _IO_2_1_stdout_;
extern struct _IO_FILE_plus _IO_2_1_stderr_;
# 364 "/usr/include/libio.h" 3 4
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);







typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
     size_t __n);







typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);


typedef int __io_close_fn (void *__cookie);
# 416 "/usr/include/libio.h" 3 4
extern int __underflow (_IO_FILE *);
extern int __uflow (_IO_FILE *);
extern int __overflow (_IO_FILE *, int);
# 458 "/usr/include/libio.h" 3 4
extern int _IO_getc (_IO_FILE *__fp);
extern int _IO_putc (int __c, _IO_FILE *__fp);
extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__));
extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__));

extern int _IO_peekc_locked (_IO_FILE *__fp);





extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__));
extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__));
extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__));
# 488 "/usr/include/libio.h" 3 4
extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
   __gnuc_va_list, int *__restrict);
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
    __gnuc_va_list);
extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t);
extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);

extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int);
extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int);

extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__));
# 76 "/usr/include/stdio.h" 2 3 4
# 89 "/usr/include/stdio.h" 3 4


typedef _G_fpos_t fpos_t;




# 141 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/bits/stdio_lim.h" 1 3 4
# 142 "/usr/include/stdio.h" 2 3 4



extern struct _IO_FILE *stdin;
extern struct _IO_FILE *stdout;
extern struct _IO_FILE *stderr;









extern int remove (__const char *__filename) __attribute__ ((__nothrow__));

extern int rename (__const char *__old, __const char *__new) __attribute__ ((__nothrow__));














extern FILE *tmpfile (void) ;
# 188 "/usr/include/stdio.h" 3 4
extern char *tmpnam (char *__s) __attribute__ ((__nothrow__)) ;





extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__)) ;
# 206 "/usr/include/stdio.h" 3 4
extern char *tempnam (__const char *__dir, __const char *__pfx)
     __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ;








extern int fclose (FILE *__stream);




extern int fflush (FILE *__stream);

# 231 "/usr/include/stdio.h" 3 4
extern int fflush_unlocked (FILE *__stream);
# 245 "/usr/include/stdio.h" 3 4






extern FILE *fopen (__const char *__restrict __filename,
      __const char *__restrict __modes) ;




extern FILE *freopen (__const char *__restrict __filename,
        __const char *__restrict __modes,
        FILE *__restrict __stream) ;
# 274 "/usr/include/stdio.h" 3 4

# 285 "/usr/include/stdio.h" 3 4
extern FILE *fdopen (int __fd, __const char *__modes) __attribute__ ((__nothrow__)) ;
# 306 "/usr/include/stdio.h" 3 4



extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__));



extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
      int __modes, size_t __n) __attribute__ ((__nothrow__));





extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
         size_t __size) __attribute__ ((__nothrow__));


extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__));








extern int fprintf (FILE *__restrict __stream,
      __const char *__restrict __format, ...);




extern int printf (__const char *__restrict __format, ...);

extern int sprintf (char *__restrict __s,
      __const char *__restrict __format, ...) __attribute__ ((__nothrow__));





extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,
       __gnuc_va_list __arg);




extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg);

extern int vsprintf (char *__restrict __s, __const char *__restrict __format,
       __gnuc_va_list __arg) __attribute__ ((__nothrow__));





extern int snprintf (char *__restrict __s, size_t __maxlen,
       __const char *__restrict __format, ...)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));

extern int vsnprintf (char *__restrict __s, size_t __maxlen,
        __const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0)));

# 400 "/usr/include/stdio.h" 3 4





extern int fscanf (FILE *__restrict __stream,
     __const char *__restrict __format, ...) ;




extern int scanf (__const char *__restrict __format, ...) ;

extern int sscanf (__const char *__restrict __s,
     __const char *__restrict __format, ...) __attribute__ ((__nothrow__));
# 443 "/usr/include/stdio.h" 3 4

# 506 "/usr/include/stdio.h" 3 4





extern int fgetc (FILE *__stream);
extern int getc (FILE *__stream);





extern int getchar (void);

# 530 "/usr/include/stdio.h" 3 4
extern int getc_unlocked (FILE *__stream);
extern int getchar_unlocked (void);
# 541 "/usr/include/stdio.h" 3 4
extern int fgetc_unlocked (FILE *__stream);











extern int fputc (int __c, FILE *__stream);
extern int putc (int __c, FILE *__stream);





extern int putchar (int __c);

# 574 "/usr/include/stdio.h" 3 4
extern int fputc_unlocked (int __c, FILE *__stream);







extern int putc_unlocked (int __c, FILE *__stream);
extern int putchar_unlocked (int __c);






extern int getw (FILE *__stream);


extern int putw (int __w, FILE *__stream);








extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
     ;






extern char *gets (char *__s) ;

# 655 "/usr/include/stdio.h" 3 4





extern int fputs (__const char *__restrict __s, FILE *__restrict __stream);





extern int puts (__const char *__s);






extern int ungetc (int __c, FILE *__stream);






extern size_t fread (void *__restrict __ptr, size_t __size,
       size_t __n, FILE *__restrict __stream) ;




extern size_t fwrite (__const void *__restrict __ptr, size_t __size,
        size_t __n, FILE *__restrict __s) ;

# 708 "/usr/include/stdio.h" 3 4
extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
         size_t __n, FILE *__restrict __stream) ;
extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size,
          size_t __n, FILE *__restrict __stream) ;








extern int fseek (FILE *__stream, long int __off, int __whence);




extern long int ftell (FILE *__stream) ;




extern void rewind (FILE *__stream);

# 744 "/usr/include/stdio.h" 3 4
extern int fseeko (FILE *__stream, __off_t __off, int __whence);




extern __off_t ftello (FILE *__stream) ;
# 763 "/usr/include/stdio.h" 3 4






extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);




extern int fsetpos (FILE *__stream, __const fpos_t *__pos);
# 786 "/usr/include/stdio.h" 3 4

# 795 "/usr/include/stdio.h" 3 4


extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__));

extern int feof (FILE *__stream) __attribute__ ((__nothrow__)) ;

extern int ferror (FILE *__stream) __attribute__ ((__nothrow__)) ;




extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__));
extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ;
extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ;








extern void perror (__const char *__s);






# 1 "/usr/include/bits/sys_errlist.h" 1 3 4
# 27 "/usr/include/bits/sys_errlist.h" 3 4
extern int sys_nerr;
extern __const char *__const sys_errlist[];
# 825 "/usr/include/stdio.h" 2 3 4




extern int fileno (FILE *__stream) __attribute__ ((__nothrow__)) ;




extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ;
# 844 "/usr/include/stdio.h" 3 4
extern FILE *popen (__const char *__command, __const char *__modes) ;





extern int pclose (FILE *__stream);





extern char *ctermid (char *__s) __attribute__ ((__nothrow__));
# 884 "/usr/include/stdio.h" 3 4
extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__));



extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__)) ;


extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__));
# 914 "/usr/include/stdio.h" 3 4

# 111 "src/memwatch.c" 2
# 1 "/usr/include/stdlib.h" 1 3 4
# 33 "/usr/include/stdlib.h" 3 4
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 326 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 3 4
typedef long int wchar_t;
# 34 "/usr/include/stdlib.h" 2 3 4


# 96 "/usr/include/stdlib.h" 3 4


typedef struct
  {
    int quot;
    int rem;
  } div_t;



typedef struct
  {
    long int quot;
    long int rem;
  } ldiv_t;



# 140 "/usr/include/stdlib.h" 3 4
extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__)) ;




extern double atof (__const char *__nptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;

extern int atoi (__const char *__nptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;

extern long int atol (__const char *__nptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;





__extension__ extern long long int atoll (__const char *__nptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;





extern double strtod (__const char *__restrict __nptr,
        char **__restrict __endptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;

# 182 "/usr/include/stdlib.h" 3 4


extern long int strtol (__const char *__restrict __nptr,
   char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;

extern unsigned long int strtoul (__const char *__restrict __nptr,
      char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;




__extension__
extern long long int strtoq (__const char *__restrict __nptr,
        char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;

__extension__
extern unsigned long long int strtouq (__const char *__restrict __nptr,
           char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;





__extension__
extern long long int strtoll (__const char *__restrict __nptr,
         char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;

__extension__
extern unsigned long long int strtoull (__const char *__restrict __nptr,
     char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;

# 311 "/usr/include/stdlib.h" 3 4
extern char *l64a (long int __n) __attribute__ ((__nothrow__)) ;


extern long int a64l (__const char *__s)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;




# 1 "/usr/include/sys/types.h" 1 3 4
# 29 "/usr/include/sys/types.h" 3 4






typedef __u_char u_char;
typedef __u_short u_short;
typedef __u_int u_int;
typedef __u_long u_long;
typedef __quad_t quad_t;
typedef __u_quad_t u_quad_t;
typedef __fsid_t fsid_t;




typedef __loff_t loff_t;



typedef __ino_t ino_t;
# 62 "/usr/include/sys/types.h" 3 4
typedef __dev_t dev_t;




typedef __gid_t gid_t;




typedef __mode_t mode_t;




typedef __nlink_t nlink_t;




typedef __uid_t uid_t;





typedef __off_t off_t;
# 100 "/usr/include/sys/types.h" 3 4
typedef __pid_t pid_t;




typedef __id_t id_t;




typedef __ssize_t ssize_t;





typedef __daddr_t daddr_t;
typedef __caddr_t caddr_t;





typedef __key_t key_t;
# 133 "/usr/include/sys/types.h" 3 4
# 1 "/usr/include/time.h" 1 3 4
# 75 "/usr/include/time.h" 3 4


typedef __time_t time_t;



# 93 "/usr/include/time.h" 3 4
typedef __clockid_t clockid_t;
# 105 "/usr/include/time.h" 3 4
typedef __timer_t timer_t;
# 134 "/usr/include/sys/types.h" 2 3 4
# 147 "/usr/include/sys/types.h" 3 4
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 148 "/usr/include/sys/types.h" 2 3 4



typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
# 195 "/usr/include/sys/types.h" 3 4
typedef int int8_t __attribute__ ((__mode__ (__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__ ((__mode__ (__DI__)));


typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));

typedef int register_t __attribute__ ((__mode__ (__word__)));
# 217 "/usr/include/sys/types.h" 3 4
# 1 "/usr/include/endian.h" 1 3 4
# 37 "/usr/include/endian.h" 3 4
# 1 "/usr/include/bits/endian.h" 1 3 4
# 38 "/usr/include/endian.h" 2 3 4
# 218 "/usr/include/sys/types.h" 2 3 4


# 1 "/usr/include/sys/select.h" 1 3 4
# 31 "/usr/include/sys/select.h" 3 4
# 1 "/usr/include/bits/select.h" 1 3 4
# 32 "/usr/include/sys/select.h" 2 3 4


# 1 "/usr/include/bits/sigset.h" 1 3 4
# 24 "/usr/include/bits/sigset.h" 3 4
typedef int __sig_atomic_t;




typedef struct
  {
    unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
  } __sigset_t;
# 35 "/usr/include/sys/select.h" 2 3 4



typedef __sigset_t sigset_t;





# 1 "/usr/include/time.h" 1 3 4
# 121 "/usr/include/time.h" 3 4
struct timespec
  {
    __time_t tv_sec;
    long int tv_nsec;
  };
# 45 "/usr/include/sys/select.h" 2 3 4

# 1 "/usr/include/bits/time.h" 1 3 4
# 69 "/usr/include/bits/time.h" 3 4
struct timeval
  {
    __time_t tv_sec;
    __suseconds_t tv_usec;
  };
# 47 "/usr/include/sys/select.h" 2 3 4


typedef __suseconds_t suseconds_t;





typedef long int __fd_mask;
# 67 "/usr/include/sys/select.h" 3 4
typedef struct
  {






    __fd_mask __fds_bits[1024 / (8 * sizeof (__fd_mask))];


  } fd_set;






typedef __fd_mask fd_mask;
# 99 "/usr/include/sys/select.h" 3 4

# 109 "/usr/include/sys/select.h" 3 4
extern int select (int __nfds, fd_set *__restrict __readfds,
     fd_set *__restrict __writefds,
     fd_set *__restrict __exceptfds,
     struct timeval *__restrict __timeout);
# 121 "/usr/include/sys/select.h" 3 4
extern int pselect (int __nfds, fd_set *__restrict __readfds,
      fd_set *__restrict __writefds,
      fd_set *__restrict __exceptfds,
      const struct timespec *__restrict __timeout,
      const __sigset_t *__restrict __sigmask);



# 221 "/usr/include/sys/types.h" 2 3 4


# 1 "/usr/include/sys/sysmacros.h" 1 3 4
# 30 "/usr/include/sys/sysmacros.h" 3 4
__extension__
extern unsigned int gnu_dev_major (unsigned long long int __dev)
     __attribute__ ((__nothrow__));
__extension__
extern unsigned int gnu_dev_minor (unsigned long long int __dev)
     __attribute__ ((__nothrow__));
__extension__
extern unsigned long long int gnu_dev_makedev (unsigned int __major,
            unsigned int __minor)
     __attribute__ ((__nothrow__));
# 224 "/usr/include/sys/types.h" 2 3 4
# 235 "/usr/include/sys/types.h" 3 4
typedef __blkcnt_t blkcnt_t;



typedef __fsblkcnt_t fsblkcnt_t;



typedef __fsfilcnt_t fsfilcnt_t;
# 270 "/usr/include/sys/types.h" 3 4
# 1 "/usr/include/bits/pthreadtypes.h" 1 3 4
# 36 "/usr/include/bits/pthreadtypes.h" 3 4
typedef unsigned long int pthread_t;


typedef union
{
  char __size[36];
  long int __align;
} pthread_attr_t;


typedef struct __pthread_internal_slist
{
  struct __pthread_internal_slist *__next;
} __pthread_slist_t;




typedef union
{
  struct __pthread_mutex_s
  {
    int __lock;
    unsigned int __count;
    int __owner;


    int __kind;
    unsigned int __nusers;
    __extension__ union
    {
      int __spins;
      __pthread_slist_t __list;
    };
  } __data;
  char __size[24];
  long int __align;
} pthread_mutex_t;

typedef union
{
  char __size[4];
  long int __align;
} pthread_mutexattr_t;




typedef union
{
  struct
  {
    int __lock;
    unsigned int __futex;
    __extension__ unsigned long long int __total_seq;
    __extension__ unsigned long long int __wakeup_seq;
    __extension__ unsigned long long int __woken_seq;
    void *__mutex;
    unsigned int __nwaiters;
    unsigned int __broadcast_seq;
  } __data;
  char __size[48];
  __extension__ long long int __align;
} pthread_cond_t;

typedef union
{
  char __size[4];
  long int __align;
} pthread_condattr_t;



typedef unsigned int pthread_key_t;



typedef int pthread_once_t;





typedef union
{
  struct
  {
    int __lock;
    unsigned int __nr_readers;
    unsigned int __readers_wakeup;
    unsigned int __writer_wakeup;
    unsigned int __nr_readers_queued;
    unsigned int __nr_writers_queued;


    unsigned char __flags;
    unsigned char __shared;
    unsigned char __pad1;
    unsigned char __pad2;
    int __writer;
  } __data;
  char __size[32];
  long int __align;
} pthread_rwlock_t;

typedef union
{
  char __size[8];
  long int __align;
} pthread_rwlockattr_t;





typedef volatile int pthread_spinlock_t;




typedef union
{
  char __size[20];
  long int __align;
} pthread_barrier_t;

typedef union
{
  char __size[4];
  int __align;
} pthread_barrierattr_t;
# 271 "/usr/include/sys/types.h" 2 3 4



# 321 "/usr/include/stdlib.h" 2 3 4






extern long int random (void) __attribute__ ((__nothrow__));


extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__));





extern char *initstate (unsigned int __seed, char *__statebuf,
   size_t __statelen) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));



extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));







struct random_data
  {
    int32_t *fptr;
    int32_t *rptr;
    int32_t *state;
    int rand_type;
    int rand_deg;
    int rand_sep;
    int32_t *end_ptr;
  };

extern int random_r (struct random_data *__restrict __buf,
       int32_t *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));

extern int srandom_r (unsigned int __seed, struct random_data *__buf)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));

extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
   size_t __statelen,
   struct random_data *__restrict __buf)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 4)));

extern int setstate_r (char *__restrict __statebuf,
         struct random_data *__restrict __buf)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));






extern int rand (void) __attribute__ ((__nothrow__));

extern void srand (unsigned int __seed) __attribute__ ((__nothrow__));




extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__));







extern double drand48 (void) __attribute__ ((__nothrow__));
extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern long int lrand48 (void) __attribute__ ((__nothrow__));
extern long int nrand48 (unsigned short int __xsubi[3])
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern long int mrand48 (void) __attribute__ ((__nothrow__));
extern long int jrand48 (unsigned short int __xsubi[3])
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern void srand48 (long int __seedval) __attribute__ ((__nothrow__));
extern unsigned short int *seed48 (unsigned short int __seed16v[3])
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));





struct drand48_data
  {
    unsigned short int __x[3];
    unsigned short int __old_x[3];
    unsigned short int __c;
    unsigned short int __init;
    unsigned long long int __a;
  };


extern int drand48_r (struct drand48_data *__restrict __buffer,
        double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
extern int erand48_r (unsigned short int __xsubi[3],
        struct drand48_data *__restrict __buffer,
        double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern int lrand48_r (struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
extern int nrand48_r (unsigned short int __xsubi[3],
        struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern int mrand48_r (struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
extern int jrand48_r (unsigned short int __xsubi[3],
        struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));

extern int seed48_r (unsigned short int __seed16v[3],
       struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));

extern int lcong48_r (unsigned short int __param[7],
        struct drand48_data *__buffer)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));









extern void *malloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ;

extern void *calloc (size_t __nmemb, size_t __size)
     __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ;










extern void *realloc (void *__ptr, size_t __size)
     __attribute__ ((__nothrow__)) __attribute__ ((__warn_unused_result__));

extern void free (void *__ptr) __attribute__ ((__nothrow__));




extern void cfree (void *__ptr) __attribute__ ((__nothrow__));



# 1 "/usr/include/alloca.h" 1 3 4
# 25 "/usr/include/alloca.h" 3 4
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 26 "/usr/include/alloca.h" 2 3 4







extern void *alloca (size_t __size) __attribute__ ((__nothrow__));






# 498 "/usr/include/stdlib.h" 2 3 4




extern void *valloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ;




extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;




extern void abort (void) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));



extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));





extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));






extern void exit (int __status) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));

# 543 "/usr/include/stdlib.h" 3 4


extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;




extern char *__secure_getenv (__const char *__name)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;





extern int putenv (char *__string) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));





extern int setenv (__const char *__name, __const char *__value, int __replace)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));


extern int unsetenv (__const char *__name) __attribute__ ((__nothrow__));






extern int clearenv (void) __attribute__ ((__nothrow__));
# 583 "/usr/include/stdlib.h" 3 4
extern char *mktemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;
# 594 "/usr/include/stdlib.h" 3 4
extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) ;
# 614 "/usr/include/stdlib.h" 3 4
extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;
# 640 "/usr/include/stdlib.h" 3 4





extern int system (__const char *__command) ;

# 662 "/usr/include/stdlib.h" 3 4
extern char *realpath (__const char *__restrict __name,
         char *__restrict __resolved) __attribute__ ((__nothrow__)) ;






typedef int (*__compar_fn_t) (__const void *, __const void *);









extern void *bsearch (__const void *__key, __const void *__base,
        size_t __nmemb, size_t __size, __compar_fn_t __compar)
     __attribute__ ((__nonnull__ (1, 2, 5))) ;



extern void qsort (void *__base, size_t __nmemb, size_t __size,
     __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));



extern int abs (int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ;
extern long int labs (long int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ;












extern div_t div (int __numer, int __denom)
     __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ;
extern ldiv_t ldiv (long int __numer, long int __denom)
     __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ;

# 727 "/usr/include/stdlib.h" 3 4
extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ;




extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ;




extern char *gcvt (double __value, int __ndigit, char *__buf)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))) ;




extern char *qecvt (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ;
extern char *qfcvt (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ;
extern char *qgcvt (long double __value, int __ndigit, char *__buf)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))) ;




extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign, char *__restrict __buf,
     size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));
extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign, char *__restrict __buf,
     size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));

extern int qecvt_r (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign,
      char *__restrict __buf, size_t __len)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));
extern int qfcvt_r (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign,
      char *__restrict __buf, size_t __len)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));







extern int mblen (__const char *__s, size_t __n) __attribute__ ((__nothrow__)) ;


extern int mbtowc (wchar_t *__restrict __pwc,
     __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__)) ;


extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__)) ;



extern size_t mbstowcs (wchar_t *__restrict __pwcs,
   __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__));

extern size_t wcstombs (char *__restrict __s,
   __const wchar_t *__restrict __pwcs, size_t __n)
     __attribute__ ((__nothrow__));








extern int rpmatch (__const char *__response) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ;
# 832 "/usr/include/stdlib.h" 3 4
extern int posix_openpt (int __oflag) ;
# 867 "/usr/include/stdlib.h" 3 4
extern int getloadavg (double __loadavg[], int __nelem)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
# 883 "/usr/include/stdlib.h" 3 4

# 112 "src/memwatch.c" 2
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h" 1 3 4
# 105 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stdarg.h" 3 4
typedef __gnuc_va_list va_list;
# 113 "src/memwatch.c" 2
# 1 "/usr/include/string.h" 1 3 4
# 28 "/usr/include/string.h" 3 4





# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 34 "/usr/include/string.h" 2 3 4




extern void *memcpy (void *__restrict __dest,
       __const void *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern void *memmove (void *__dest, __const void *__src, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));






extern void *memccpy (void *__restrict __dest, __const void *__restrict __src,
        int __c, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));





extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern int memcmp (__const void *__s1, __const void *__s2, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));


extern void *memchr (__const void *__s, int __c, size_t __n)
      __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));

# 82 "/usr/include/string.h" 3 4


extern char *strcpy (char *__restrict __dest, __const char *__restrict __src)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));

extern char *strncpy (char *__restrict __dest,
        __const char *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern char *strcat (char *__restrict __dest, __const char *__restrict __src)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));

extern char *strncat (char *__restrict __dest, __const char *__restrict __src,
        size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern int strcmp (__const char *__s1, __const char *__s2)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));

extern int strncmp (__const char *__s1, __const char *__s2, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));


extern int strcoll (__const char *__s1, __const char *__s2)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));

extern size_t strxfrm (char *__restrict __dest,
         __const char *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));

# 130 "/usr/include/string.h" 3 4
extern char *strdup (__const char *__s)
     __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
# 165 "/usr/include/string.h" 3 4


extern char *strchr (__const char *__s, int __c)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));

extern char *strrchr (__const char *__s, int __c)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));

# 181 "/usr/include/string.h" 3 4



extern size_t strcspn (__const char *__s, __const char *__reject)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));


extern size_t strspn (__const char *__s, __const char *__accept)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));

extern char *strpbrk (__const char *__s, __const char *__accept)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));

extern char *strstr (__const char *__haystack, __const char *__needle)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));



extern char *strtok (char *__restrict __s, __const char *__restrict __delim)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));




extern char *__strtok_r (char *__restrict __s,
    __const char *__restrict __delim,
    char **__restrict __save_ptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3)));

extern char *strtok_r (char *__restrict __s, __const char *__restrict __delim,
         char **__restrict __save_ptr)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3)));
# 240 "/usr/include/string.h" 3 4


extern size_t strlen (__const char *__s)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));

# 254 "/usr/include/string.h" 3 4


extern char *strerror (int __errnum) __attribute__ ((__nothrow__));

# 270 "/usr/include/string.h" 3 4
extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
# 294 "/usr/include/string.h" 3 4
extern void __bzero (void *__s, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));



extern void bcopy (__const void *__src, void *__dest, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));


extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern int bcmp (__const void *__s1, __const void *__s2, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));


extern char *index (__const char *__s, int __c)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));


extern char *rindex (__const char *__s, int __c)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));



extern int ffs (int __i) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
# 331 "/usr/include/string.h" 3 4
extern int strcasecmp (__const char *__s1, __const char *__s2)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));


extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
# 354 "/usr/include/string.h" 3 4
extern char *strsep (char **__restrict __stringp,
       __const char *__restrict __delim)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
# 432 "/usr/include/string.h" 3 4

# 114 "src/memwatch.c" 2
# 1 "/usr/include/signal.h" 1 3 4
# 31 "/usr/include/signal.h" 3 4


# 1 "/usr/include/bits/sigset.h" 1 3 4
# 104 "/usr/include/bits/sigset.h" 3 4
extern int __sigismember (__const __sigset_t *, int);
extern int __sigaddset (__sigset_t *, int);
extern int __sigdelset (__sigset_t *, int);
# 34 "/usr/include/signal.h" 2 3 4







typedef __sig_atomic_t sig_atomic_t;

# 58 "/usr/include/signal.h" 3 4
# 1 "/usr/include/bits/signum.h" 1 3 4
# 59 "/usr/include/signal.h" 2 3 4
# 75 "/usr/include/signal.h" 3 4
typedef void (*__sighandler_t) (int);




extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
     __attribute__ ((__nothrow__));
# 90 "/usr/include/signal.h" 3 4


extern __sighandler_t signal (int __sig, __sighandler_t __handler)
     __attribute__ ((__nothrow__));
# 104 "/usr/include/signal.h" 3 4

# 117 "/usr/include/signal.h" 3 4
extern int kill (__pid_t __pid, int __sig) __attribute__ ((__nothrow__));






extern int killpg (__pid_t __pgrp, int __sig) __attribute__ ((__nothrow__));




extern int raise (int __sig) __attribute__ ((__nothrow__));




extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
     __attribute__ ((__nothrow__));
extern int gsignal (int __sig) __attribute__ ((__nothrow__));




extern void psignal (int __sig, __const char *__s);
# 153 "/usr/include/signal.h" 3 4
extern int __sigpause (int __sig_or_mask, int __is_sig);
# 181 "/usr/include/signal.h" 3 4
extern int sigblock (int __mask) __attribute__ ((__nothrow__)) __attribute__ ((__deprecated__));


extern int sigsetmask (int __mask) __attribute__ ((__nothrow__)) __attribute__ ((__deprecated__));


extern int siggetmask (void) __attribute__ ((__nothrow__)) __attribute__ ((__deprecated__));
# 201 "/usr/include/signal.h" 3 4
typedef __sighandler_t sig_t;







# 1 "/usr/include/time.h" 1 3 4
# 210 "/usr/include/signal.h" 2 3 4


# 1 "/usr/include/bits/siginfo.h" 1 3 4
# 25 "/usr/include/bits/siginfo.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 26 "/usr/include/bits/siginfo.h" 2 3 4







typedef union sigval
  {
    int sival_int;
    void *sival_ptr;
  } sigval_t;
# 51 "/usr/include/bits/siginfo.h" 3 4
typedef struct siginfo
  {
    int si_signo;
    int si_errno;

    int si_code;

    union
      {
 int _pad[((128 / sizeof (int)) - 3)];


 struct
   {
     __pid_t si_pid;
     __uid_t si_uid;
   } _kill;


 struct
   {
     int si_tid;
     int si_overrun;
     sigval_t si_sigval;
   } _timer;


 struct
   {
     __pid_t si_pid;
     __uid_t si_uid;
     sigval_t si_sigval;
   } _rt;


 struct
   {
     __pid_t si_pid;
     __uid_t si_uid;
     int si_status;
     __clock_t si_utime;
     __clock_t si_stime;
   } _sigchld;


 struct
   {
     void *si_addr;
   } _sigfault;


 struct
   {
     long int si_band;
     int si_fd;
   } _sigpoll;
      } _sifields;
  } siginfo_t;
# 129 "/usr/include/bits/siginfo.h" 3 4
enum
{
  SI_ASYNCNL = -60,

  SI_TKILL = -6,

  SI_SIGIO,

  SI_ASYNCIO,

  SI_MESGQ,

  SI_TIMER,

  SI_QUEUE,

  SI_USER,

  SI_KERNEL = 0x80

};



enum
{
  ILL_ILLOPC = 1,

  ILL_ILLOPN,

  ILL_ILLADR,

  ILL_ILLTRP,

  ILL_PRVOPC,

  ILL_PRVREG,

  ILL_COPROC,

  ILL_BADSTK

};


enum
{
  FPE_INTDIV = 1,

  FPE_INTOVF,

  FPE_FLTDIV,

  FPE_FLTOVF,

  FPE_FLTUND,

  FPE_FLTRES,

  FPE_FLTINV,

  FPE_FLTSUB

};


enum
{
  SEGV_MAPERR = 1,

  SEGV_ACCERR

};


enum
{
  BUS_ADRALN = 1,

  BUS_ADRERR,

  BUS_OBJERR

};


enum
{
  TRAP_BRKPT = 1,

  TRAP_TRACE

};


enum
{
  CLD_EXITED = 1,

  CLD_KILLED,

  CLD_DUMPED,

  CLD_TRAPPED,

  CLD_STOPPED,

  CLD_CONTINUED

};


enum
{
  POLL_IN = 1,

  POLL_OUT,

  POLL_MSG,

  POLL_ERR,

  POLL_PRI,

  POLL_HUP

};
# 273 "/usr/include/bits/siginfo.h" 3 4
typedef struct sigevent
  {
    sigval_t sigev_value;
    int sigev_signo;
    int sigev_notify;

    union
      {
 int _pad[((64 / sizeof (int)) - 3)];



 __pid_t _tid;

 struct
   {
     void (*_function) (sigval_t);
     void *_attribute;
   } _sigev_thread;
      } _sigev_un;
  } sigevent_t;






enum
{
  SIGEV_SIGNAL = 0,

  SIGEV_NONE,

  SIGEV_THREAD,


  SIGEV_THREAD_ID = 4

};
# 213 "/usr/include/signal.h" 2 3 4



extern int sigemptyset (sigset_t *__set) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern int sigfillset (sigset_t *__set) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern int sigaddset (sigset_t *__set, int __signo) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern int sigdelset (sigset_t *__set, int __signo) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));


extern int sigismember (__const sigset_t *__set, int __signo)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
# 246 "/usr/include/signal.h" 3 4
# 1 "/usr/include/bits/sigaction.h" 1 3 4
# 25 "/usr/include/bits/sigaction.h" 3 4
struct sigaction
  {


    union
      {

 __sighandler_t sa_handler;

 void (*sa_sigaction) (int, siginfo_t *, void *);
      }
    __sigaction_handler;







    __sigset_t sa_mask;


    int sa_flags;


    void (*sa_restorer) (void);
  };
# 247 "/usr/include/signal.h" 2 3 4


extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
   sigset_t *__restrict __oset) __attribute__ ((__nothrow__));






extern int sigsuspend (__const sigset_t *__set) __attribute__ ((__nonnull__ (1)));


extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
        struct sigaction *__restrict __oact) __attribute__ ((__nothrow__));


extern int sigpending (sigset_t *__set) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));






extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
     __attribute__ ((__nonnull__ (1, 2)));






extern int sigwaitinfo (__const sigset_t *__restrict __set,
   siginfo_t *__restrict __info) __attribute__ ((__nonnull__ (1)));






extern int sigtimedwait (__const sigset_t *__restrict __set,
    siginfo_t *__restrict __info,
    __const struct timespec *__restrict __timeout)
     __attribute__ ((__nonnull__ (1)));



extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
     __attribute__ ((__nothrow__));
# 304 "/usr/include/signal.h" 3 4
extern __const char *__const _sys_siglist[65];
extern __const char *__const sys_siglist[65];


struct sigvec
  {
    __sighandler_t sv_handler;
    int sv_mask;

    int sv_flags;

  };
# 328 "/usr/include/signal.h" 3 4
extern int sigvec (int __sig, __const struct sigvec *__vec,
     struct sigvec *__ovec) __attribute__ ((__nothrow__));



# 1 "/usr/include/bits/sigcontext.h" 1 3 4
# 28 "/usr/include/bits/sigcontext.h" 3 4
# 1 "/usr/include/asm/sigcontext.h" 1 3 4
# 19 "/usr/include/asm/sigcontext.h" 3 4
struct _fpreg {
 unsigned short significand[4];
 unsigned short exponent;
};

struct _fpxreg {
 unsigned short significand[4];
 unsigned short exponent;
 unsigned short padding[3];
};

struct _xmmreg {
 unsigned long element[4];
};

struct _fpstate {

 unsigned long cw;
 unsigned long sw;
 unsigned long tag;
 unsigned long ipoff;
 unsigned long cssel;
 unsigned long dataoff;
 unsigned long datasel;
 struct _fpreg _st[8];
 unsigned short status;
 unsigned short magic;


 unsigned long _fxsr_env[6];
 unsigned long mxcsr;
 unsigned long reserved;
 struct _fpxreg _fxsr_st[8];
 struct _xmmreg _xmm[8];
 unsigned long padding[56];
};



struct sigcontext {
 unsigned short gs, __gsh;
 unsigned short fs, __fsh;
 unsigned short es, __esh;
 unsigned short ds, __dsh;
 unsigned long edi;
 unsigned long esi;
 unsigned long ebp;
 unsigned long esp;
 unsigned long ebx;
 unsigned long edx;
 unsigned long ecx;
 unsigned long eax;
 unsigned long trapno;
 unsigned long err;
 unsigned long eip;
 unsigned short cs, __csh;
 unsigned long eflags;
 unsigned long esp_at_signal;
 unsigned short ss, __ssh;
 struct _fpstate * fpstate;
 unsigned long oldmask;
 unsigned long cr2;
};
# 29 "/usr/include/bits/sigcontext.h" 2 3 4
# 334 "/usr/include/signal.h" 2 3 4


extern int sigreturn (struct sigcontext *__scp) __attribute__ ((__nothrow__));






# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 344 "/usr/include/signal.h" 2 3 4




extern int siginterrupt (int __sig, int __interrupt) __attribute__ ((__nothrow__));

# 1 "/usr/include/bits/sigstack.h" 1 3 4
# 26 "/usr/include/bits/sigstack.h" 3 4
struct sigstack
  {
    void *ss_sp;
    int ss_onstack;
  };



enum
{
  SS_ONSTACK = 1,

  SS_DISABLE

};
# 50 "/usr/include/bits/sigstack.h" 3 4
typedef struct sigaltstack
  {
    void *ss_sp;
    int ss_flags;
    size_t ss_size;
  } stack_t;
# 351 "/usr/include/signal.h" 2 3 4
# 359 "/usr/include/signal.h" 3 4
extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
     __attribute__ ((__nothrow__)) __attribute__ ((__deprecated__));



extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
   struct sigaltstack *__restrict __oss) __attribute__ ((__nothrow__));
# 389 "/usr/include/signal.h" 3 4
# 1 "/usr/include/bits/sigthread.h" 1 3 4
# 31 "/usr/include/bits/sigthread.h" 3 4
extern int pthread_sigmask (int __how,
       __const __sigset_t *__restrict __newmask,
       __sigset_t *__restrict __oldmask)__attribute__ ((__nothrow__));


extern int pthread_kill (pthread_t __threadid, int __signo) __attribute__ ((__nothrow__));
# 390 "/usr/include/signal.h" 2 3 4






extern int __libc_current_sigrtmin (void) __attribute__ ((__nothrow__));

extern int __libc_current_sigrtmax (void) __attribute__ ((__nothrow__));




# 115 "src/memwatch.c" 2
# 1 "/usr/include/setjmp.h" 1 3 4
# 28 "/usr/include/setjmp.h" 3 4


# 1 "/usr/include/bits/setjmp.h" 1 3 4
# 29 "/usr/include/bits/setjmp.h" 3 4
typedef int __jmp_buf[6];
# 31 "/usr/include/setjmp.h" 2 3 4
# 1 "/usr/include/bits/sigset.h" 1 3 4
# 32 "/usr/include/setjmp.h" 2 3 4



struct __jmp_buf_tag
  {




    __jmp_buf __jmpbuf;
    int __mask_was_saved;
    __sigset_t __saved_mask;
  };




typedef struct __jmp_buf_tag jmp_buf[1];



extern int setjmp (jmp_buf __env) __attribute__ ((__nothrow__));






extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __attribute__ ((__nothrow__));




extern int _setjmp (struct __jmp_buf_tag __env[1]) __attribute__ ((__nothrow__));
# 78 "/usr/include/setjmp.h" 3 4




extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
     __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));







extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
     __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));







typedef struct __jmp_buf_tag sigjmp_buf[1];
# 110 "/usr/include/setjmp.h" 3 4
extern void siglongjmp (sigjmp_buf __env, int __val)
     __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));



# 116 "src/memwatch.c" 2
# 1 "/usr/include/time.h" 1 3 4
# 31 "/usr/include/time.h" 3 4








# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/stddef.h" 1 3 4
# 40 "/usr/include/time.h" 2 3 4



# 1 "/usr/include/bits/time.h" 1 3 4
# 44 "/usr/include/time.h" 2 3 4
# 59 "/usr/include/time.h" 3 4


typedef __clock_t clock_t;



# 132 "/usr/include/time.h" 3 4


struct tm
{
  int tm_sec;
  int tm_min;
  int tm_hour;
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_wday;
  int tm_yday;
  int tm_isdst;


  long int tm_gmtoff;
  __const char *tm_zone;




};








struct itimerspec
  {
    struct timespec it_interval;
    struct timespec it_value;
  };


struct sigevent;
# 181 "/usr/include/time.h" 3 4



extern clock_t clock (void) __attribute__ ((__nothrow__));


extern time_t time (time_t *__timer) __attribute__ ((__nothrow__));


extern double difftime (time_t __time1, time_t __time0)
     __attribute__ ((__nothrow__)) __attribute__ ((__const__));


extern time_t mktime (struct tm *__tp) __attribute__ ((__nothrow__));





extern size_t strftime (char *__restrict __s, size_t __maxsize,
   __const char *__restrict __format,
   __const struct tm *__restrict __tp) __attribute__ ((__nothrow__));

# 229 "/usr/include/time.h" 3 4



extern struct tm *gmtime (__const time_t *__timer) __attribute__ ((__nothrow__));



extern struct tm *localtime (__const time_t *__timer) __attribute__ ((__nothrow__));





extern struct tm *gmtime_r (__const time_t *__restrict __timer,
       struct tm *__restrict __tp) __attribute__ ((__nothrow__));



extern struct tm *localtime_r (__const time_t *__restrict __timer,
          struct tm *__restrict __tp) __attribute__ ((__nothrow__));





extern char *asctime (__const struct tm *__tp) __attribute__ ((__nothrow__));


extern char *ctime (__const time_t *__timer) __attribute__ ((__nothrow__));







extern char *asctime_r (__const struct tm *__restrict __tp,
   char *__restrict __buf) __attribute__ ((__nothrow__));


extern char *ctime_r (__const time_t *__restrict __timer,
        char *__restrict __buf) __attribute__ ((__nothrow__));




extern char *__tzname[2];
extern int __daylight;
extern long int __timezone;




extern char *tzname[2];



extern void tzset (void) __attribute__ ((__nothrow__));



extern int daylight;
extern long int timezone;





extern int stime (__const time_t *__when) __attribute__ ((__nothrow__));
# 312 "/usr/include/time.h" 3 4
extern time_t timegm (struct tm *__tp) __attribute__ ((__nothrow__));


extern time_t timelocal (struct tm *__tp) __attribute__ ((__nothrow__));


extern int dysize (int __year) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
# 327 "/usr/include/time.h" 3 4
extern int nanosleep (__const struct timespec *__requested_time,
        struct timespec *__remaining);



extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __attribute__ ((__nothrow__));


extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __attribute__ ((__nothrow__));


extern int clock_settime (clockid_t __clock_id, __const struct timespec *__tp)
     __attribute__ ((__nothrow__));






extern int clock_nanosleep (clockid_t __clock_id, int __flags,
       __const struct timespec *__req,
       struct timespec *__rem);


extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __attribute__ ((__nothrow__));




extern int timer_create (clockid_t __clock_id,
    struct sigevent *__restrict __evp,
    timer_t *__restrict __timerid) __attribute__ ((__nothrow__));


extern int timer_delete (timer_t __timerid) __attribute__ ((__nothrow__));


extern int timer_settime (timer_t __timerid, int __flags,
     __const struct itimerspec *__restrict __value,
     struct itimerspec *__restrict __ovalue) __attribute__ ((__nothrow__));


extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
     __attribute__ ((__nothrow__));


extern int timer_getoverrun (timer_t __timerid) __attribute__ ((__nothrow__));
# 416 "/usr/include/time.h" 3 4

# 117 "src/memwatch.c" 2
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h" 1 3 4
# 11 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h" 3 4
# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h" 1 3 4






# 1 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h" 1 3 4
# 122 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h" 3 4
# 1 "/usr/include/limits.h" 1 3 4
# 145 "/usr/include/limits.h" 3 4
# 1 "/usr/include/bits/posix1_lim.h" 1 3 4
# 153 "/usr/include/bits/posix1_lim.h" 3 4
# 1 "/usr/include/bits/local_lim.h" 1 3 4
# 36 "/usr/include/bits/local_lim.h" 3 4
# 1 "/usr/include/linux/limits.h" 1 3 4
# 37 "/usr/include/bits/local_lim.h" 2 3 4
# 154 "/usr/include/bits/posix1_lim.h" 2 3 4
# 146 "/usr/include/limits.h" 2 3 4



# 1 "/usr/include/bits/posix2_lim.h" 1 3 4
# 150 "/usr/include/limits.h" 2 3 4
# 123 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h" 2 3 4
# 8 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/syslimits.h" 2 3 4
# 12 "/usr/lib/gcc/i386-redhat-linux/4.1.2/include/limits.h" 2 3 4
# 118 "src/memwatch.c" 2
# 1 "/mnt/hgfs/src/testing/include/memwatch.h" 1
# 409 "/mnt/hgfs/src/testing/include/memwatch.h"
void mwInit( void );
void mwTerm( void );
void mwAbort( void );
# 444 "/mnt/hgfs/src/testing/include/memwatch.h"
void mwFlushNow( void );
void mwDoFlush( int onoff );
void mwLimit( long bytes );
unsigned mwGrab( unsigned kilobytes );
unsigned mwDrop( unsigned kilobytes );
void mwNoMansLand( int mw_nml_level );
void mwStatistics( int level );
void mwFreeBufferInfo( int onoff );
void mwAutoCheck( int onoff );
void mwCalcCheck( void );
void mwDumpCheck( void );
void * mwMark( void *p, const char *description, const char *file, unsigned line );
void * mwUnmark( void *p, const char *file, unsigned line );
# 480 "/mnt/hgfs/src/testing/include/memwatch.h"
int mwIsReadAddr( const void *p, unsigned len );
int mwIsSafeAddr( void *p, unsigned len );
int mwTest( const char *file, int line, int mw_test_flags );
int mwTestBuffer( const char *file, int line, void *p );
int mwAssert( int, const char*, const char*, int );
int mwVerify( int, const char*, const char*, int );
# 510 "/mnt/hgfs/src/testing/include/memwatch.h"
void mwTrace( const char* format_string, ... );
void mwPuts( const char* text );
void mwSetOutFunc( void (*func)(int) );
void mwSetAriFunc( int (*func)(const char*) );
void mwSetAriAction( int mw_ari_value );
int mwAriHandler( const char* cause );
void mwBreakOut( const char* cause );
# 534 "/mnt/hgfs/src/testing/include/memwatch.h"
void* mwMalloc( size_t, const char*, int );
void* mwMalloc_( size_t );
void* mwRealloc( void *, size_t, const char*, int );
void* mwRealloc_( void *, size_t );
void* mwCalloc( size_t, size_t, const char*, int );
void* mwCalloc_( size_t, size_t );
void mwFree( void*, const char*, int );
void mwFree_( void* );
char* mwStrdup( const char *, const char*, int );
# 119 "src/memwatch.c" 2


# 1 "/usr/include/ctype.h" 1 3 4
# 30 "/usr/include/ctype.h" 3 4

# 48 "/usr/include/ctype.h" 3 4
enum
{
  _ISupper = ((0) < 8 ? ((1 << (0)) << 8) : ((1 << (0)) >> 8)),
  _ISlower = ((1) < 8 ? ((1 << (1)) << 8) : ((1 << (1)) >> 8)),
  _ISalpha = ((2) < 8 ? ((1 << (2)) << 8) : ((1 << (2)) >> 8)),
  _ISdigit = ((3) < 8 ? ((1 << (3)) << 8) : ((1 << (3)) >> 8)),
  _ISxdigit = ((4) < 8 ? ((1 << (4)) << 8) : ((1 << (4)) >> 8)),
  _ISspace = ((5) < 8 ? ((1 << (5)) << 8) : ((1 << (5)) >> 8)),
  _ISprint = ((6) < 8 ? ((1 << (6)) << 8) : ((1 << (6)) >> 8)),
  _ISgraph = ((7) < 8 ? ((1 << (7)) << 8) : ((1 << (7)) >> 8)),
  _ISblank = ((8) < 8 ? ((1 << (8)) << 8) : ((1 << (8)) >> 8)),
  _IScntrl = ((9) < 8 ? ((1 << (9)) << 8) : ((1 << (9)) >> 8)),
  _ISpunct = ((10) < 8 ? ((1 << (10)) << 8) : ((1 << (10)) >> 8)),
  _ISalnum = ((11) < 8 ? ((1 << (11)) << 8) : ((1 << (11)) >> 8))
};
# 81 "/usr/include/ctype.h" 3 4
extern __const unsigned short int **__ctype_b_loc (void)
     __attribute__ ((__const));
extern __const __int32_t **__ctype_tolower_loc (void)
     __attribute__ ((__const));
extern __const __int32_t **__ctype_toupper_loc (void)
     __attribute__ ((__const));
# 96 "/usr/include/ctype.h" 3 4






extern int isalnum (int) __attribute__ ((__nothrow__));
extern int isalpha (int) __attribute__ ((__nothrow__));
extern int iscntrl (int) __attribute__ ((__nothrow__));
extern int isdigit (int) __attribute__ ((__nothrow__));
extern int islower (int) __attribute__ ((__nothrow__));
extern int isgraph (int) __attribute__ ((__nothrow__));
extern int isprint (int) __attribute__ ((__nothrow__));
extern int ispunct (int) __attribute__ ((__nothrow__));
extern int isspace (int) __attribute__ ((__nothrow__));
extern int isupper (int) __attribute__ ((__nothrow__));
extern int isxdigit (int) __attribute__ ((__nothrow__));



extern int tolower (int __c) __attribute__ ((__nothrow__));


extern int toupper (int __c) __attribute__ ((__nothrow__));


# 142 "/usr/include/ctype.h" 3 4
extern int isascii (int __c) __attribute__ ((__nothrow__));



extern int toascii (int __c) __attribute__ ((__nothrow__));



extern int _toupper (int) __attribute__ ((__nothrow__));
extern int _tolower (int) __attribute__ ((__nothrow__));
# 323 "/usr/include/ctype.h" 3 4

# 122 "src/memwatch.c" 2
# 189 "src/memwatch.c"
typedef unsigned char mwBYTE;
# 222 "src/memwatch.c"
typedef unsigned long mwDWORD;
# 254 "src/memwatch.c"
typedef struct mwData_ mwData;
struct mwData_ {
    mwData* prev;
    mwData* next;
    const char* file;
    long count;
    long check;



    size_t size;
    int line;
    unsigned flag;
    };


typedef struct mwStat_ mwStat;
struct mwStat_ {
    mwStat* next;
    const char* file;
    long total;
    long num;
    long max;
    long curr;
    int line;
    };


typedef struct mwGrabData_ mwGrabData;
struct mwGrabData_ {
    mwGrabData* next;
    int type;
    char blob[ 1024 - sizeof(mwGrabData*) - sizeof(int) ];
    };

typedef struct mwMarker_ mwMarker;
struct mwMarker_ {
    void *host;
    char *text;
    mwMarker *next;
    int level;
    };
# 309 "src/memwatch.c"
static int mwInited = 0;
static int mwInfoWritten = 0;
static int mwUseAtexit = 0;
static FILE* mwLog = ((void *)0);
static int mwFlushing = 0;
static int mwStatLevel = 0;
static int mwNML = 0;
static int mwFBI = 0;
static long mwAllocLimit = 0L;
static int mwUseLimit = 0;

static long mwNumCurAlloc = 0L;
static mwData* mwHead = ((void *)0);
static mwData* mwTail = ((void *)0);
static int mwDataSize = 0;
static unsigned char mwOverflowZoneTemplate[] = "mEmwAtch";
static int mwOverflowZoneSize = 4;

static void (*mwOutFunction)(int) = ((void *)0);
static int (*mwAriFunction)(const char*) = ((void *)0);
static int mwAriAction = 0x04;

static char mwPrintBuf[2048 +8];

static unsigned long mwCounter = 0L;
static long mwErrors = 0L;

static int mwTestFlags = 0;
static int mwTestAlways = 0;

static FILE* mwLogB1 = ((void *)0);
static int mwFlushingB1 = 0;

static mwStat* mwStatList = ((void *)0);
static long mwStatTotAlloc = 0L;
static long mwStatMaxAlloc = 0L;
static long mwStatNumAlloc = 0L;
static long mwStatCurAlloc = 0L;
static long mwNmlNumAlloc = 0L;
static long mwNmlCurAlloc = 0L;

static mwGrabData* mwGrabList = ((void *)0);
static long mwGrabSize = 0L;

static void * mwLastFree[64];
static const char *mwLFfile[64];
static int mwLFline[64];
static int mwLFcur = 0;

static mwMarker* mwFirstMark = ((void *)0);

static FILE* mwLogB2 = ((void *)0);
static int mwFlushingB2 = 0;
# 371 "src/memwatch.c"
static void mwAutoInit( void );
static FILE* mwLogR( void );
static void mwLogW( FILE* );
static int mwFlushR( void );
static void mwFlushW( int );
static void mwFlush( void );
static void mwIncErr( void );
static void mwUnlink( mwData*, const char* file, int line );
static int mwRelink( mwData*, const char* file, int line );
static int mwIsHeapOK( mwData *mw );
static int mwIsOwned( mwData* mw, const char* file, int line );
static int mwTestBuf( mwData* mw, const char* file, int line );
static void mwDefaultOutFunc( int );
static void mwWrite( const char* format, ... );
static void mwLogFile( const char* name );
static size_t mwFreeUp( size_t, int );
static const void *mwTestMem( const void *, unsigned, int );
static int mwStrCmpI( const char *s1, const char *s2 );
static int mwTestNow( const char *file, int line, int always_invoked );
static void mwDropAll( void );
static const char *mwGrabType( int type );
static unsigned mwGrab_( unsigned kb, int type, int silent );
static unsigned mwDrop_( unsigned kb, int type, int silent );
static int mwARI( const char* text );
static void mwStatReport( void );
static mwStat* mwStatGet( const char*, int, int );
static void mwStatAlloc( size_t, const char*, int );
static void mwStatFree( size_t, const char*, int );
static int mwCheckOF( const void * p );
static void mwWriteOF( void * p );
static char mwDummy( char c );
# 413 "src/memwatch.c"
void mwInit( void ) {
    time_t tid;

    if( mwInited++ > 0 ) return;

 ;


    if( mwLogR() == ((void *)0) ) mwLogFile( "memwatch.log" );
    if( mwLogR() == ((void *)0) ) {
        int i;
        char buf[32];



        for( i=1; i<100; i++ ) {
            sprintf( buf, "memwat%02d.log", i );
            mwLogFile( buf );
            if( mwLogR() != ((void *)0) ) break;
            }
        }


    mwStatList = ((void *)0);
    mwStatTotAlloc = 0L;
    mwStatCurAlloc = 0L;
    mwStatMaxAlloc = 0L;
    mwStatNumAlloc = 0L;
 mwNmlCurAlloc = 0L;
 mwNmlNumAlloc = 0L;


 mwDataSize = sizeof(mwData);
 while( mwDataSize % 4 ) mwDataSize ++;


    if( !mwInfoWritten ) {
        mwInfoWritten = 1;
        (void) time( &tid );
        mwWrite(
            "\n============="
            " MEMWATCH " "2.71" " Copyright (C) 1992-1999 Johan Lindh "
            "=============\n");
        mwWrite( "\nStarted at %s\n", ctime( &tid ) );


  mwWrite( "Modes: " );




        mwWrite( "__STDC__ " );





  mwWrite( "32-bit " );




  mwWrite( "mwDWORD==(" "unsigned long" ")\n" );
  mwWrite( "mwROUNDALLOC==%d sizeof(mwData)==%d mwDataSize==%d\n",
   4, sizeof(mwData), mwDataSize );
# 509 "src/memwatch.c"
        mwWrite( "\n" );
        mwFlush();
        }

    if( mwUseAtexit ) (void) atexit( mwAbort );
    return;
    }

void mwAbort( void ) {
    mwData *mw;
    mwMarker *mrk;
    char *data;
    time_t tid;
    int c, i, j;
 int errors;

    tid = time( ((void *)0) );
    mwWrite( "\nStopped at %s\n", ctime( &tid) );

    if( !mwInited )
        mwWrite( "internal: mwAbort(): MEMWATCH not initialized!\n" );


    mwDropAll();


    while( mwFirstMark ) {
        mrk = mwFirstMark->next;
        mwWrite( "mark: %p: %s\n", mwFirstMark->host, mwFirstMark->text );
        free( mwFirstMark->text );
        free( mwFirstMark );
        mwFirstMark = mrk;
        mwErrors ++;
        }


 errors = 0;
    while( mwHead != ((void *)0) && errors < 3 ) {
  if( !mwIsOwned(mwHead, "src/memwatch.c", 547 ) ) {
   if( errors < 3 )
   {
    errors ++;
    mwWrite( "internal: NML/unfreed scan restarting\n" );
    mwFlush();
    mwHead = mwHead;
    continue;
   }
   mwWrite( "internal: NML/unfreed scan aborted, heap too damaged\n" );
   mwFlush();
   break;
   }
        mwFlushW(0);
        if( !(mwHead->flag & 0x0001) ) {
            mwErrors++;
            data = ((char*)mwHead)+mwDataSize;
            mwWrite( "unfreed: <%ld> %s(%d), %ld bytes at %p ",
                mwHead->count, mwHead->file, mwHead->line, (long)mwHead->size, data+mwOverflowZoneSize );
            if( mwCheckOF( data ) ) {
                mwWrite( "[underflowed] ");
                mwFlush();
                }
            if( mwCheckOF( (data+mwOverflowZoneSize+mwHead->size) ) ) {
                mwWrite( "[overflowed] ");
                mwFlush();
                }
            mwWrite( " \t{" );
            j = 16; if( mwHead->size < 16 ) j = (int) mwHead->size;
            for( i=0;i<16;i++ ) {
                if( i<j ) mwWrite( "%02X ",
                    (unsigned char) *(data+mwOverflowZoneSize+i) );
                else mwWrite( ".. " );
                }
            for( i=0;i<j;i++ ) {
                c = *(data+mwOverflowZoneSize+i);
                if( c < 32 || c > 126 ) c = '.';
                mwWrite( "%c", c );
                }
            mwWrite( "}\n" );
   mw = mwHead;
   mwUnlink( mw, "src/memwatch.c", 588 );
            free( mw );
            }
        else {
            data = ((char*)mwHead) + mwDataSize + mwOverflowZoneSize;
            if( mwTestMem( data, mwHead->size, 0xFC ) ) {
                mwErrors++;
                mwWrite( "wild pointer: <%ld> NoMansLand %p alloc'd at %s(%d)\n",
                    mwHead->count, data + mwOverflowZoneSize, mwHead->file, mwHead->line );
                mwFlush();
                }
   mwNmlNumAlloc --;
   mwNmlCurAlloc -= mwHead->size;
   mw = mwHead;
   mwUnlink( mw, "src/memwatch.c", 602 );
            free( mw );
            }
        }

 if( mwNmlNumAlloc ) mwWrite("internal: NoMansLand block counter %ld, not zero\n", mwNmlNumAlloc );
 if( mwNmlCurAlloc ) mwWrite("internal: NoMansLand byte counter %ld, not zero\n", mwNmlCurAlloc );


    mwStatReport();
    mwFlush();

    mwInited = 0;
    mwHead = mwTail = ((void *)0);
    if( mwErrors )
        fprintf(mwLog,"MEMWATCH detected %ld anomalies\n",mwErrors);
    mwLogFile( ((void *)0) );
    mwErrors = 0;

    ;

    }

void mwTerm( void ) {
    if( mwInited == 1 )
    {
        mwAbort();
        return;
    }
    if( !mwInited )
        mwWrite("internal: mwTerm(): MEMWATCH has not been started!\n");
    else
        mwInited --;
    }

void mwStatistics( int level )
{
    mwAutoInit();
    if( level<0 ) level=0;
    if( mwStatLevel != level )
    {
  mwWrite( "statistics: now collecting on a %s basis\n",
   level<1?"global":(level<2?"module":"line") );
     mwStatLevel = level;
 }
}

void mwAutoCheck( int onoff ) {
    mwAutoInit();
    mwTestAlways = onoff;
    if( onoff ) mwTestFlags = 0xFFFF;
    }

void mwSetOutFunc( void (*func)(int) ) {
    mwAutoInit();
    mwOutFunction = func;
    }

static void mwWriteOF( void *p )
{
 int i;
 unsigned char *ptr;
 ptr = (unsigned char*) p;
 for( i=0; i<mwOverflowZoneSize; i++ )
 {
  *(ptr+i) = mwOverflowZoneTemplate[i%8];
 }
 return;
}

static int mwCheckOF( const void *p )
{
 int i;
 const unsigned char *ptr;
 ptr = (const unsigned char *) p;
 for( i=0; i<mwOverflowZoneSize; i++ )
 {
  if( *(ptr+i) != mwOverflowZoneTemplate[i%8] )
   return 1;
 }
 return 0;
}

int mwTest( const char *file, int line, int items ) {
    mwAutoInit();
    mwTestFlags = items;
    return mwTestNow( file, line, 0 );
    }





int mwTestBuffer( const char *file, int line, void *p ) {
    mwData* mw;

    mwAutoInit();


    mw = (mwData*) ( (mwData*) (void*) ( ((char*)p)-mwDataSize-mwOverflowZoneSize ) );

    if( mwIsOwned( mw, file, line ) ) {
        return mwTestBuf( mw, file, line );
  }
 return 1;
 }

void mwBreakOut( const char* cause ) {
    fprintf(mwLog, "breakout: %s\n", cause);
    mwWrite("breakout: %s\n", cause );
    return;
    }




void * mwMark( void *p, const char *desc, const char *file, unsigned line ) {
    mwMarker *mrk;
    unsigned n, isnew;
    char *buf;
    int tot, oflow = 0;
    char wherebuf[128];

    mwAutoInit();
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);

    if( desc == ((void *)0) ) desc = "unknown";
    if( file == ((void *)0) ) file = "unknown";

    tot = sprintf( wherebuf, "%.48s called from %s(%d)", desc, file, line );
    if( tot >= (int)sizeof(wherebuf) ) { wherebuf[sizeof(wherebuf)-1] = 0; oflow = 1; }

    if( p == ((void *)0) ) {
        mwWrite("mark: %s(%d), no mark for NULL:'%s' may be set\n", file, line, desc );
        return p;
        }

 if( mwFirstMark != ((void *)0) && !mwIsReadAddr( mwFirstMark, sizeof( mwMarker ) ) )
 {
  mwWrite("mark: %s(%d), mwFirstMark (%p) is trashed, can't mark for %s\n",
   file, line, mwFirstMark, desc );
  return p;
 }

    for( mrk=mwFirstMark; mrk; mrk=mrk->next )
 {
  if( mrk->next != ((void *)0) && !mwIsReadAddr( mrk->next, sizeof( mwMarker ) ) )
  {
   mwWrite("mark: %s(%d), mark(%p)->next(%p) is trashed, can't mark for %s\n",
    file, line, mrk, mrk->next, desc );
   return p;
  }
  if( mrk->host == p ) break;
 }

    if( mrk == ((void *)0) ) {
        isnew = 1;
        mrk = (mwMarker*) malloc( sizeof( mwMarker ) );
        if( mrk == ((void *)0) ) {
            mwWrite("mark: %s(%d), no mark for %p:'%s', out of memory\n", file, line, p, desc );
            return p;
            }
  mrk->next = ((void *)0);
        n = 0;
        }
    else {
        isnew = 0;
        n = strlen( mrk->text );
        }

    n += strlen( wherebuf );
    buf = (char*) malloc( n+3 );
    if( buf == ((void *)0) ) {
        if( isnew ) free( mrk );
        mwWrite("mark: %s(%d), no mark for %p:'%s', out of memory\n", file, line, p, desc );
        return p;
        }

    if( isnew ) {
        memcpy( buf, wherebuf, n+1 );
        mrk->next = mwFirstMark;
        mrk->host = p;
        mrk->text = buf;
        mrk->level = 1;
        mwFirstMark = mrk;
        }
    else {
        strcpy( buf, mrk->text );
        strcat( buf, ", " );
        strcat( buf, wherebuf );
        free( mrk->text );
        mrk->text = buf;
        mrk->level ++;
        }

    if( oflow ) {
        mwIncErr();
        mwTrace( " [WARNING: OUTPUT BUFFER OVERFLOW - SYSTEM UNSTABLE]\n" );
        }
    return p;
    }

void* mwUnmark( void *p, const char *file, unsigned line ) {
    mwMarker *mrk, *prv;
    mrk = mwFirstMark;
    prv = ((void *)0);
    while( mrk ) {
        if( mrk->host == p ) {
            if( mrk->level < 2 ) {
                if( prv ) prv->next = mrk->next;
                else mwFirstMark = mrk->next;
                free( mrk->text );
                free( mrk );
                return p;
                }
            mrk->level --;
            return p;
            }
        prv = mrk;
        mrk = mrk->next;
        }
    mwWrite("mark: %s(%d), no mark found for %p\n", file, line, p );
    return p;
    }






static int mwARI( const char *estr ) {
    char inbuf[81];
    int c;
    fprintf(mwLog, "\n%s\nMEMWATCH: Abort, Retry or Ignore? ", estr);
    (void) fgets(inbuf,sizeof(inbuf),stdin);
 for( c=0; inbuf[c] && inbuf[c] <= ' '; c++ ) ;
    c = inbuf[c];
    if( c == 'R' || c == 'r' ) {
        mwBreakOut( estr );
        return 0x02;
        }
    if( c == 'I' || c == 'i' ) return 0x01;
    return 0x04;
    }


int mwAriHandler( const char *estr ) {
    mwAutoInit();
    return mwARI( estr );
    }


void mwSetAriFunc( int (*func)(const char *) ) {
    mwAutoInit();
    mwAriFunction = func;
    }





void* mwMalloc( size_t size, const char* file, int line) {
    size_t needed;
    mwData *mw;
    char *ptr;
    void *p;

    mwAutoInit();

 ;

    if(mwTestAlways) (void)mwTestNow(file,line,1);

    mwCounter ++;
    needed = mwDataSize + mwOverflowZoneSize*2 + size;
    if( needed < size )
    {

     return ((void *)0);
    }


    if( mwUseLimit && ((long)size + mwStatCurAlloc > mwAllocLimit) ) {
        mwWrite( "limit fail: <%ld> %s(%d), %ld wanted %ld available\n",
            mwCounter, file, line, (long)size, mwAllocLimit - mwStatCurAlloc );
        mwIncErr();
        mwFlush();
  ;
        return ((void *)0);
        }

    mw = (mwData*) malloc( needed );
    if( mw == ((void *)0) ) {
        if( mwFreeUp(needed,0) >= needed ) {
            mw = (mwData*) malloc(needed);
            if( mw == ((void *)0) ) {
                mwWrite( "internal: mwFreeUp(%u) reported success, but malloc() fails\n", needed );
                mwIncErr();
                mwFlush();
                }
            }
        if( mw == ((void *)0) ) {
            mwWrite( "fail: <%ld> %s(%d), %ld wanted %ld allocated\n",
                mwCounter, file, line, (long)size, mwStatCurAlloc );
            mwIncErr();
            mwFlush();
   ;
            return ((void *)0);
            }
        }

    mw->count = mwCounter;
    mw->prev = ((void *)0);
    mw->next = mwHead;
    mw->file = file;
    mw->size = size;
    mw->line = line;
    mw->flag = 0;
    mw->check = (0xFE0180L^(long)mw->count^(long)mw->size^(long)mw->line);

    if( mwHead ) mwHead->prev = mw;
    mwHead = mw;
    if( mwTail == ((void *)0) ) mwTail = mw;

    ptr = ((char*)mw) + mwDataSize;
 mwWriteOF( ptr );
    ptr += mwOverflowZoneSize;
    p = ptr;
    memset( ptr, 0xFE, size );
    ptr += size;
    mwWriteOF( ptr );

    mwNumCurAlloc ++;
    mwStatCurAlloc += (long) size;
    mwStatTotAlloc += (long) size;
    if( mwStatCurAlloc > mwStatMaxAlloc )
        mwStatMaxAlloc = mwStatCurAlloc;
    mwStatNumAlloc ++;

    if( mwStatLevel ) mwStatAlloc( size, file, line );

 ;
    return p;
    }

void* mwRealloc( void *p, size_t size, const char* file, int line) {
    int oldUseLimit, i;
    mwData *mw;
    char *ptr;

    mwAutoInit();

    if( p == ((void *)0) ) return mwMalloc( size, file, line );
    if( size == 0 ) { mwFree( p, file, line ); return ((void *)0); }

 ;


    mw = (mwData*) ( (mwData*) (void*) ( ((char*)p)-mwDataSize-mwOverflowZoneSize ) );
    if( mwIsOwned( mw, file, line ) ) {


  if( mw->flag & 0x0001 )
  {
            mwIncErr();
   if( *((unsigned char*)(mw)+mwDataSize+mwOverflowZoneSize) != 0xFC )
   {
    mwWrite( "internal: <%ld> %s(%d), no-mans-land MW-%p is corrupted\n",
     mwCounter, file, line, mw );
   }
   goto check_dbl_free;
  }


        if( mwUseLimit && ((long)size + mwStatCurAlloc - (long)mw->size > mwAllocLimit) ) {
            if(mwTestAlways) (void)mwTestNow(file,line,1);
            mwCounter ++;
            mwWrite( "limit fail: <%ld> %s(%d), %ld wanted %ld available\n",
                mwCounter, file, line, (unsigned long)size - mw->size, mwAllocLimit - mwStatCurAlloc );
            mwIncErr();
            mwFlush();
   ;
            return ((void *)0);
            }


        oldUseLimit = mwUseLimit;
        mwUseLimit = 0;
        ptr = (char*) mwMalloc( size, file, line );
        if( ptr != ((void *)0) ) {
            if( size < mw->size )
                memcpy( ptr, p, size );
            else
                memcpy( ptr, p, mw->size );
            mwFree( p, file, line );
            }
        mwUseLimit = oldUseLimit;
  ;
        return (void*) ptr;
        }




check_dbl_free:
    for(i=0;i<64;i++) {
        if( mwLastFree[i] == p ) {
            mwIncErr();
            mwWrite( "realloc: <%ld> %s(%d), %p was"
                " freed from %s(%d)\n",
                mwCounter, file, line, p,
                mwLFfile[i], mwLFline[i] );
            mwFlush();
   ;
            return ((void *)0);
            }
        }


    mwIncErr();
    mwWrite( "realloc: <%ld> %s(%d), unknown pointer %p\n",
        mwCounter, file, line, p );
    mwFlush();
 ;
    return ((void *)0);
    }

char *mwStrdup( const char* str, const char* file, int line ) {
    size_t len;
    char *newstring;

 ;

    if( str == ((void *)0) ) {
        mwIncErr();
        mwWrite( "strdup: <%ld> %s(%d), strdup(NULL) called\n",
            mwCounter, file, line );
        mwFlush();
  ;
        return ((void *)0);
        }

    len = strlen( str ) + 1;
    newstring = (char*) mwMalloc( len, file, line );
    if( newstring != ((void *)0) ) memcpy( newstring, str, len );
 ;
    return newstring;
    }

void mwFree( void* p, const char* file, int line ) {
    int i;
    mwData* mw;
    char buffer[ sizeof(mwData) + (4*3) + 64 ];


    if( file == ((void *)0) ) {
        mwFree_( p );
  ;
        return;
        }

    mwAutoInit();

 ;
    if(mwTestAlways) (void)mwTestNow(file,line,1);
    mwCounter ++;


    if( p == ((void *)0) ) {
        mwWrite( "NULL free: <%ld> %s(%d), NULL pointer free'd\n",
            mwCounter, file, line );
        mwFlush();
  ;
        return;
        }


    mw = (mwData*) ( (mwData*) (void*) ( ((char*)p)-mwDataSize-mwOverflowZoneSize ) );

    if( mwIsOwned( mw, file, line ) ) {
        (void) mwTestBuf( mw, file, line );


  if( mw->flag & 0x0001 )
  {
   if( *(((unsigned char*)mw)+mwDataSize+mwOverflowZoneSize) != 0xFC )
   {
    mwWrite( "internal: <%ld> %s(%d), no-mans-land MW-%p is corrupted\n",
     mwCounter, file, line, mw );
   }
   goto check_dbl_free;
  }


        mwNumCurAlloc --;
        mwStatCurAlloc -= (long) mw->size;
        if( mwStatLevel ) mwStatFree( mw->size, mw->file, mw->line );


        if( mwNML ) {
            mw->flag |= 0x0001;
   mwNmlNumAlloc ++;
   mwNmlCurAlloc += (long) mw->size;
            memset( ((char*)mw)+mwDataSize+mwOverflowZoneSize, 0xFC, mw->size );
            }
        else {

            mwUnlink( mw, file, line );
            memset( mw, 0xFD,
                mw->size + mwDataSize+mwOverflowZoneSize+mwOverflowZoneSize );
            if( mwFBI ) {
                memset( mw, '.', mwDataSize + mwOverflowZoneSize );
                sprintf( buffer, "FBI<%ld>%s(%d)", mwCounter, file, line );
                strncpy( (char*)(void*)mw, buffer, mwDataSize + mwOverflowZoneSize );
                }
            free( mw );
            }


        mwLFfile[ mwLFcur ] = file;
        mwLFline[ mwLFcur ] = line;
        mwLastFree[ mwLFcur++ ] = p;
        if( mwLFcur == 64 ) mwLFcur = 0;

  ;
        return;
        }


check_dbl_free:
    for(i=0;i<64;i++) {
        if( mwLastFree[i] == p ) {
            mwIncErr();
            mwWrite( "double-free: <%ld> %s(%d), %p was"
                " freed from %s(%d)\n",
                mwCounter, file, line, p,
                mwLFfile[i], mwLFline[i] );
            mwFlush();
   ;
            return;
            }
        }


    mwIncErr();
    mwWrite( "WILD free: <%ld> %s(%d), unknown pointer %p\n",
        mwCounter, file, line, p );
    mwFlush();
 ;
    return;
    }

void* mwCalloc( size_t a, size_t b, const char *file, int line ) {
    void *p;
    size_t size = a * b;
    p = mwMalloc( size, file, line );
    if( p == ((void *)0) ) return ((void *)0);
    memset( p, 0, size );
    return p;
    }

void mwFree_( void *p ) {
 ;
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
 ;
    free(p);
    }

void* mwMalloc_( size_t size ) {
 ;
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
 ;
    return malloc( size );
    }

void* mwRealloc_( void *p, size_t size ) {
 ;
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
 ;
    return realloc( p, size );
    }

void* mwCalloc_( size_t a, size_t b ) {
 ;
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
 ;
    return calloc( a, b );
    }

void mwFlushNow( void ) {
    if( mwLogR() ) fflush( mwLogR() );
    return;
    }

void mwDoFlush( int onoff ) {
    mwFlushW( onoff<1?0:onoff );
    if( onoff ) if( mwLogR() ) fflush( mwLogR() );
    return;
    }

void mwLimit( long lim ) {
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    mwWrite("limit: old limit = ");
    if( !mwAllocLimit ) mwWrite( "none" );
    else mwWrite( "%ld bytes", mwAllocLimit );
    mwWrite( ", new limit = ");
    if( !lim ) {
        mwWrite( "none\n" );
        mwUseLimit = 0;
        }
    else {
        mwWrite( "%ld bytes\n", lim );
        mwUseLimit = 1;
        }
    mwAllocLimit = lim;
    mwFlush();
    }

void mwSetAriAction( int action ) {
 ;
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    mwAriAction = action;
 ;
    return;
    }

int mwAssert( int exp, const char *exps, const char *fn, int ln ) {
    int i;
    char buffer[2048 +8];
    if( exp ) {
     return 0;
     }
    mwAutoInit();
 ;
    if(mwTestAlways) (void)mwTestNow(fn,ln,1);
    mwIncErr();
    mwCounter++;
    mwWrite( "assert trap: <%ld> %s(%d), %s\n", mwCounter, fn, ln, exps );
    if( mwAriFunction != ((void *)0) ) {
        sprintf( buffer, "MEMWATCH: assert trap: %s(%d), %s", fn, ln, exps );
        i = (*mwAriFunction)(buffer);
  switch( i ) {
   case 0x01:
             mwWrite( "assert trap: <%ld> IGNORED - execution continues\n", mwCounter );
    ;
             return 0;
   case 0x02:
             mwWrite( "assert trap: <%ld> RETRY - executing again\n", mwCounter );
    ;
             return 1;
   }
        }
    else {
        if( mwAriAction & 0x01 ) {
            mwWrite( "assert trap: <%ld> AUTO IGNORED - execution continues\n", mwCounter );
   ;
            return 0;
            }
        fprintf(mwLog,"\nMEMWATCH: assert trap: %s(%d), %s\n", fn, ln, exps );
        }

    mwFlush();
    (void) mwTestNow( fn, ln, 1 );
    mwFlush();

 if( mwAriAction & 0x10 ) {


     mwFlush();

  i = *((int*)((void *)0));
  mwDummy( (char)i );

  }

 ;
    exit(255);




    return 0;

    }

int mwVerify( int exp, const char *exps, const char *fn, int ln ) {
    int i;
    char buffer[2048 +8];
    if( exp ) {
     return 0;
     }
    mwAutoInit();
 ;
    if(mwTestAlways) (void)mwTestNow(fn,ln,1);
    mwIncErr();
    mwCounter++;
    mwWrite( "verify trap: <%ld> %s(%d), %s\n", mwCounter, fn, ln, exps );
    if( mwAriFunction != ((void *)0) ) {
        sprintf( buffer, "MEMWATCH: verify trap: %s(%d), %s", fn, ln, exps );
        i = (*mwAriFunction)(buffer);
        if( i == 0 ) {
            mwWrite( "verify trap: <%ld> IGNORED - execution continues\n", mwCounter );
   ;
            return 0;
            }
        if( i == 1 ) {
            mwWrite( "verify trap: <%ld> RETRY - executing again\n", mwCounter );
   ;
            return 1;
            }
        }
    else {
        if( mwAriAction & 0x10 ) {


      mwFlush();

            i = *((int*)((void *)0));
   mwDummy( (char)i );

            }
        if( mwAriAction & 0x01 ) {
            mwWrite( "verify trap: <%ld> AUTO IGNORED - execution continues\n", mwCounter );
   ;
            return 0;
            }
        fprintf(mwLog,"\nMEMWATCH: verify trap: %s(%d), %s\n", fn, ln, exps );
        }
    mwFlush();
    (void) mwTestNow( fn, ln, 1 );
    mwFlush();
 ;
 exit(255);




    return 0;

    }

void mwTrace( const char *format, ... ) {
    int tot, oflow = 0;
    va_list mark;

    mwAutoInit();
 ;
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    if( mwOutFunction == ((void *)0) ) mwOutFunction = mwDefaultOutFunc;

    __builtin_va_start(mark,format);
    tot = vsprintf( mwPrintBuf, format, mark );
    __builtin_va_end(mark);
    if( tot >= 2048 ) { mwPrintBuf[2048] = 0; oflow = 1; }
    for(tot=0;mwPrintBuf[tot];tot++)
        (*mwOutFunction)( mwPrintBuf[tot] );
    if( oflow ) {
        mwIncErr();
        mwTrace( " [WARNING: OUTPUT BUFFER OVERFLOW - SYSTEM UNSTABLE]\n" );
        }

    mwFlush();
 ;
    }






unsigned mwGrab( unsigned kb ) {
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    return mwGrab_( kb, 0xFB, 0 );
    }

unsigned mwDrop( unsigned kb ) {
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    return mwDrop_( kb, 0xFB, 0 );
    }

static void mwDropAll() {
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    (void) mwDrop_( 0, 0xFB, 0 );
    (void) mwDrop_( 0, 0xFC, 0 );
    if( mwGrabList != ((void *)0) )
        mwWrite( "internal: the grab list is not empty after mwDropAll()\n");
    }

static const char *mwGrabType( int type ) {
    switch( type ) {
        case 0xFB:
            return "grabbed";
        case 0xFC:
            return "no-mans-land";
        default:

            ;
        }
    return "<unknown type>";
    }

static unsigned mwGrab_( unsigned kb, int type, int silent ) {
    unsigned i = kb;
    mwGrabData *gd;
    if( !kb ) i = kb = 65000U;

    for(;kb;kb--) {
        if( mwUseLimit &&
            (mwStatCurAlloc + mwGrabSize + (long)sizeof(mwGrabData) > mwAllocLimit) ) {
            if( !silent ) {
                mwWrite("grabbed: all allowed memory to %s (%u kb)\n",
                    mwGrabType(type), i-kb);
                mwFlush();
                }
            return i-kb;
            }
        gd = (mwGrabData*) malloc( sizeof(mwGrabData) );
        if( gd == ((void *)0) ) {
            if( !silent ) {
                mwWrite("grabbed: all available memory to %s (%u kb)\n",
                    mwGrabType(type), i-kb);
                mwFlush();
                }
            return i-kb;
            }
        mwGrabSize += (long) sizeof(mwGrabData);
        gd->next = mwGrabList;
        memset( gd->blob, type, sizeof(gd->blob) );
        gd->type = type;
        mwGrabList = gd;
        }
    if( !silent ) {
        mwWrite("grabbed: %u kilobytes of %s memory\n", i, mwGrabType(type) );
        mwFlush();
        }
    return i;
    }

static unsigned mwDrop_( unsigned kb, int type, int silent ) {
    unsigned i = kb;
    mwGrabData *gd,*tmp,*pr;
    const void *p;

    if( mwGrabList == ((void *)0) && kb == 0 ) return 0;
    if( !kb ) i = kb = 60000U;

    pr = ((void *)0);
    gd = mwGrabList;
    for(;kb;) {
        if( gd == ((void *)0) ) {
            if( i-kb > 0 && !silent ) {
                mwWrite("dropped: all %s memory (%u kb)\n", mwGrabType(type), i-kb);
                mwFlush();
                }
            return i-kb;
            }
        if( gd->type == type ) {
            if( pr ) pr->next = gd->next;
            kb --;
            tmp = gd;
            if( mwGrabList == gd ) mwGrabList = gd->next;
            gd = gd->next;
            p = mwTestMem( tmp->blob, sizeof( tmp->blob ), type );
            if( p != ((void *)0) ) {
                mwWrite( "wild pointer: <%ld> %s memory hit at %p\n",
                    mwCounter, mwGrabType(type), p );
                mwFlush();
                }
            mwGrabSize -= (long) sizeof(mwGrabData);
            free( tmp );
            }
        else {
            pr = gd;
            gd = gd->next;
            }
        }
    if( !silent ) {
        mwWrite("dropped: %u kilobytes of %s memory\n", i, mwGrabType(type) );
        mwFlush();
        }
    return i;
    }





void mwNoMansLand( int level ) {
    mwAutoInit();
    if(mwTestAlways) (void)mwTestNow(((void *)0),0,1);
    switch( level ) {
        case 0:
            (void) mwDrop_( 0, 0xFC, 0 );
            break;
        case 1:
            break;
        case 2:
            (void) mwGrab_( 0, 0xFC, 0 );
            break;
        default:
            return;
        }
    mwNML = level;
    }





static void mwAutoInit( void )
{
    if( mwInited ) return;
    mwUseAtexit = 1;
    mwInit();
    return;
}

static FILE *mwLogR() {
    if( (mwLog == mwLogB1) && (mwLog == mwLogB2) ) return mwLog;
    if( mwLog == mwLogB1 ) mwLogB2 = mwLog;
    if( mwLog == mwLogB2 ) mwLogB1 = mwLog;
    if( mwLogB1 == mwLogB2 ) mwLog = mwLogB1;
    if( (mwLog == mwLogB1) && (mwLog == mwLogB2) ) {
        mwWrite("internal: log file handle damaged and recovered\n");
        mwFlush();
        return mwLog;
        }
    fprintf(mwLog,"\nMEMWATCH: log file handle destroyed, using mwSTDERR\n" );
    mwLog = mwLogB1 = mwLogB2 = mwLog;
    return mwLog;
    }

static void mwLogW( FILE *p ) {
    mwLog = mwLogB1 = mwLogB2 = p;
    }

static int mwFlushR() {
    if( (mwFlushing == mwFlushingB1) && (mwFlushing == mwFlushingB2) ) return mwFlushing;
    if( mwFlushing == mwFlushingB1 ) mwFlushingB2 = mwFlushing;
    if( mwFlushing == mwFlushingB2 ) mwFlushingB1 = mwFlushing;
    if( mwFlushingB1 == mwFlushingB2 ) mwFlushing = mwFlushingB1;
    if( (mwFlushing == mwFlushingB1) && (mwFlushing == mwFlushingB2) ) {
        mwWrite("internal: flushing flag damaged and recovered\n");
        mwFlush();
        return mwFlushing;
        }
    mwWrite("internal: flushing flag destroyed, so set to true\n");
    mwFlushing = mwFlushingB1 = mwFlushingB2 = 1;
    return 1;
    }

static void mwFlushW( int n ) {
    mwFlushing = mwFlushingB1 = mwFlushingB2 = n;
    }

static void mwIncErr() {
    mwErrors++;
    mwFlushW( mwFlushR()+1 );
    mwFlush();
    }

static void mwFlush() {
    if( mwLogR() == ((void *)0) ) return;



    if( mwFlushR() ) fflush( mwLogR() );

    return;
    }

static void mwUnlink( mwData* mw, const char* file, int line ) {
    if( mw->prev == ((void *)0) ) {
        if( mwHead != mw )
            mwWrite( "internal: <%ld> %s(%d), MW-%p: link1 NULL, but not head\n",
                mwCounter, file, line, mw );
        mwHead = mw->next;
        }
    else {
        if( mw->prev->next != mw )
            mwWrite( "internal: <%ld> %s(%d), MW-%p: link1 failure\n",
                mwCounter, file, line, mw );
        else mw->prev->next = mw->next;
        }
    if( mw->next == ((void *)0) ) {
        if( mwTail != mw )
            mwWrite( "internal: <%ld> %s(%d), MW-%p: link2 NULL, but not tail\n",
                mwCounter, file, line, mw );
        mwTail = mw->prev;
        }
    else {
        if( mw->next->prev != mw )
            mwWrite( "internal: <%ld> %s(%d), MW-%p: link2 failure\n",
                mwCounter, file, line, mw );
        else mw->next->prev = mw->prev;
        }
    }






static int mwRelink( mwData* mw, const char* file, int line ) {
    int fails;
    mwData *mw1, *mw2;
    long count, size;
    mwStat *ms;

 if( file == ((void *)0) ) file = "unknown";

    if( mw == ((void *)0) ) {
        mwWrite("relink: cannot repair MW at NULL\n");
        mwFlush();
        goto emergency;
        }

    if( !mwIsSafeAddr(mw, mwDataSize) ) {
        mwWrite("relink: MW-%p is a garbage pointer\n", mw);
        mwFlush();
        goto emergency;
        }

    mwWrite("relink: <%ld> %s(%d) attempting to repair MW-%p...\n", mwCounter, file, line, mw );
    mwFlush();
    fails = 0;


    if( mwHead != mw ) {
        if( !mwIsSafeAddr( mwHead, mwDataSize ) ) {
            mwWrite("relink: failed for MW-%p; head pointer destroyed\n", mw );
            mwFlush();
            goto emergency;
            }
        for( mw1=mwHead; mw1; mw1=mw1->next ) {
            if( mw1->next == mw ) {
                mw->prev = mw1;
                break;
                }
            if( mw1->next &&
                ( !mwIsSafeAddr(mw1->next, mwDataSize ) || mw1->next->prev != mw1) ) {
                mwWrite("relink: failed for MW-%p; forward chain fragmented at MW-%p: 'next' is %p\n", mw, mw1, mw1->next );
                mwFlush();
                goto emergency;
                }
            }
        if( mw1 == ((void *)0) ) {
            mwWrite("relink: MW-%p not found in forward chain search\n", mw );
            mwFlush();
            fails ++;
            }
        }
 else
 {
  mwWrite( "relink: MW-%p is the head (first) allocation\n", mw );
  if( mw->prev != ((void *)0) )
  {
   mwWrite( "relink: MW-%p prev pointer is non-NULL, you have a wild pointer\n", mw );
   mw->prev = ((void *)0);
  }
 }


    if( mwTail != mw ) {
        if( !mwIsSafeAddr( mwTail, mwDataSize ) ) {
            mwWrite("relink: failed for MW-%p; tail pointer destroyed\n", mw );
            mwFlush();
            goto emergency;
            }
        for( mw1=mwTail; mw1; mw1=mw1->prev ) {
            if( mw1->prev == mw ) {
                mw->next = mw1;
                break;
                }
            if( mw1->prev && (!mwIsSafeAddr(mw1->prev, mwDataSize ) || mw1->prev->next != mw1) ) {
                mwWrite("relink: failed for MW-%p; reverse chain fragmented at MW-%p, 'prev' is %p\n", mw, mw1, mw1->prev );
                mwFlush();
                goto emergency;
                }
            }
        if( mw1 == ((void *)0) ) {
            mwWrite("relink: MW-%p not found in reverse chain search\n", mw );
            mwFlush();
            fails ++;
            }
        }
 else
 {
  mwWrite( "relink: MW-%p is the tail (last) allocation\n", mw );
  if( mw->next != ((void *)0) )
  {
   mwWrite( "relink: MW-%p next pointer is non-NULL, you have a wild pointer\n", mw );
   mw->next = ((void *)0);
  }
 }

    if( fails > 1 ) {
        mwWrite("relink: heap appears intact, MW-%p probably garbage pointer\n", mw );
        mwFlush();
        goto verifyok;
        }


    if( mwIsReadAddr( mw->file, 1 ) ) {
        ms = mwStatGet( mw->file, -1, 0 );
        if( ms == ((void *)0) ) mw->file = "<relinked>";
        }
    mw->check = (0xFE0180L^(long)mw->count^(long)mw->size^(long)mw->line);
    goto verifyok;


    emergency:

    if( mwHead == ((void *)0) && mwTail == ((void *)0) )
    {
        if( mwStatCurAlloc == 0 )
            mwWrite("relink: <%ld> %s(%d) heap is empty, nothing to repair\n", mwCounter, file, line );
        else
            mwWrite("relink: <%ld> %s(%d) heap damaged beyond repair\n", mwCounter, file, line );
        mwFlush();
        return 0;
    }

    mwWrite("relink: <%ld> %s(%d) attempting emergency repairs...\n", mwCounter, file, line );
    mwFlush();

 if( mwHead == ((void *)0) || mwTail == ((void *)0) )
 {
  if( mwHead == ((void *)0) ) mwWrite("relink: mwHead is NULL, but mwTail is %p\n", mwTail );
  else mwWrite("relink: mwTail is NULL, but mwHead is %p\n", mwHead );
 }

    mw1=((void *)0);
    if( mwHead != ((void *)0) )
 {
  if( !mwIsReadAddr( mwHead, mwDataSize ) || mwHead->check != (0xFE0180L^(long)mwHead->count^(long)mwHead->size^(long)mwHead->line) )
  {
   mwWrite("relink: mwHead (MW-%p) is damaged, skipping forward scan\n", mwHead );
   mwHead = ((void *)0);
   goto scan_reverse;
  }
  if( mwHead->prev != ((void *)0) )
  {
   mwWrite("relink: the mwHead pointer's 'prev' member is %p, not NULL\n", mwHead->prev );
  }
        for( mw1=mwHead; mw1; mw1=mw1->next )
  {
   if( mw1->next )
   {
    if( !mwIsReadAddr(mw1->next,mwDataSize) ||
     !mw1->next->check != (0xFE0180L^(long)mw1->count^(long)mw1->size^(long)mw1->line) ||
     mw1->next->prev != mw1 )
    {
     mwWrite("relink: forward chain's last intact MW is MW-%p, %ld %sbytes at %s(%d)\n",
      mw1, mw1->size, (mw->flag & 0x0001)?"NoMansLand ":"", mw1->file, mw1->line );
     if( mwIsReadAddr(mw1->next,mwDataSize ) )
     {
      mwWrite("relink: forward chain's first damaged MW is MW-%p, %ld %sbytes at %s(%d)\n",
       mw1->next, mw1->size, (mw->flag & 0x0001)?"NoMansLand ":"",
       mwIsReadAddr(mw1->file,16)?mw1->file:"<garbage-pointer>", mw1->line );
     }
     else
     {
      mwWrite("relink: the 'next' pointer of this MW points to %p, which is out-of-legal-access\n",
       mw1->next );
     }
     break;
    }
   }
        }
 }


scan_reverse:
    mw2=((void *)0);
    if( mwTail != ((void *)0) )
 {
  if( !mwIsReadAddr(mwTail,mwDataSize) || mwTail->check != (0xFE0180L^(long)mwTail->count^(long)mwTail->size^(long)mwTail->line) )
  {
   mwWrite("relink: mwTail (%p) is damaged, skipping reverse scan\n", mwTail );
   mwTail = ((void *)0);
   goto analyze;
  }
  if( mwTail->next != ((void *)0) )
  {
   mwWrite("relink: the mwTail pointer's 'next' member is %p, not NULL\n", mwTail->next );
  }
        for( mw2=mwTail; mw2; mw2=mw2->prev )
  {
            if( mw2->prev )
   {
    if( !mwIsReadAddr(mw2->prev,mwDataSize) ||
     !mw2->prev->check != (0xFE0180L^(long)mw2->count^(long)mw2->size^(long)mw2->line) ||
     mw2->prev->next != mw2 )
    {
     mwWrite("relink: reverse chain's last intact MW is MW-%p, %ld %sbytes at %s(%d)\n",
      mw2, mw2->size, (mw->flag & 0x0001)?"NoMansLand ":"", mw2->file, mw2->line );
     if( mwIsReadAddr(mw2->prev,mwDataSize ) )
     {
      mwWrite("relink: reverse chain's first damaged MW is MW-%p, %ld %sbytes at %s(%d)\n",
       mw2->prev, mw2->size, (mw->flag & 0x0001)?"NoMansLand ":"",
       mwIsReadAddr(mw2->file,16)?mw2->file:"<garbage-pointer>", mw2->line );
     }
     else
     {
      mwWrite("relink: the 'prev' pointer of this MW points to %p, which is out-of-legal-access\n",
       mw2->prev );
     }
     break;
    }
   }
        }
 }

analyze:
 if( mwHead == ((void *)0) && mwTail == ((void *)0) )
 {
        mwWrite("relink: both head and tail pointers damaged, aborting program\n");
        mwFlushW(1);
        mwFlush();
        abort();
 }
 if( mwHead == ((void *)0) )
 {
  mwHead = mw2;
  mwWrite("relink: heap truncated, MW-%p designated as new mwHead\n", mw2 );
  mw2->prev = ((void *)0);
  mw1 = mw2 = ((void *)0);
 }
 if( mwTail == ((void *)0) )
 {
  mwTail = mw1;
  mwWrite("relink: heap truncated, MW-%p designated as new mwTail\n", mw1 );
  mw1->next = ((void *)0);
  mw1 = mw2 = ((void *)0);
 }
    if( mw1 == ((void *)0) && mw2 == ((void *)0) &&
        mwHead->prev == ((void *)0) && mwTail->next == ((void *)0) ) {
        mwWrite("relink: verifying heap integrity...\n" );
        mwFlush();
        goto verifyok;
        }
    if( mw1 && mw2 && mw1 != mw2 ) {
        mw1->next = mw2;
        mw2->prev = mw1;
        mwWrite("relink: emergency repairs successful, assessing damage...\n");
        mwFlush();
        }
    else {
        mwWrite("relink: heap totally destroyed, aborting program\n");
        mwFlushW(1);
        mwFlush();
        abort();
        }



verifyok:
    if( !mwIsHeapOK( ((void *)0) ) ) {
        mwWrite("relink: heap verification FAILS - aborting program\n");
        mwFlushW(1);
        mwFlush();
        abort();
        }
    for( size=count=0, mw1=mwHead; mw1; mw1=mw1->next ) {
        count ++;
        size += (long) mw1->size;
        }
    if( count == mwNumCurAlloc ) {
        mwWrite("relink: successful, ");
        if( size == mwStatCurAlloc ) {
            mwWrite("no allocations lost\n");
            }
        else {
            if( mw != ((void *)0) ) {
                mwWrite("size information lost for MW-%p\n", mw);
                mw->size = 0;
                }
            }
        }
    else {
        mwWrite("relink: partial, %ld MW-blocks of %ld bytes lost\n",
   mwNmlNumAlloc+mwNumCurAlloc-count, mwNmlCurAlloc+mwStatCurAlloc-size );
        return 0;
        }

    return 1;
    }
# 1899 "src/memwatch.c"
static int mwIsHeapOK( mwData *includes_mw ) {
    int found = 0;
    mwData *mw;

    for( mw = mwHead; mw; mw=mw->next ) {
        if( includes_mw == mw ) found++;
        if( !mwIsSafeAddr( mw, mwDataSize ) ) return 0;
        if( mw->prev ) {
            if( !mwIsSafeAddr( mw->prev, mwDataSize ) ) return 0;
            if( mw==mwHead || mw->prev->next != mw ) return 0;
            }
        if( mw->next ) {
            if( !mwIsSafeAddr( mw->next, mwDataSize ) ) return 0;
            if( mw==mwTail || mw->next->prev != mw ) return 0;
            }
        else if( mw!=mwTail ) return 0;
        }

    if( includes_mw != ((void *)0) && !found ) return 0;

    return 1;
    }

static int mwIsOwned( mwData* mw, const char *file, int line ) {
    int retv;
    mwStat *ms;


    if( !mwIsSafeAddr( mw, mwDataSize ) ) return 0;


    if( mwHead == ((void *)0) && mwTail == ((void *)0) && mwStatCurAlloc == 0 )
        return 0;


    if( mw->check != (0xFE0180L^(long)mw->count^(long)mw->size^(long)mw->line) ) {

        if( mwIsHeapOK( mw ) ) {

            mwWrite( "internal: <%ld> %s(%d), checksum for MW-%p is incorrect\n",
                mwCounter, file, line, mw );
            mwIncErr();
            if( mwIsReadAddr( mw->file, 1 ) ) {
                ms = mwStatGet( mw->file, -1, 0 );
                if( ms == ((void *)0) ) mw->file = "<relinked>";
                }
            else mw->file = "<unknown>";
            mw->size = 0;
            mw->check = (0xFE0180L^(long)mw->count^(long)mw->size^(long)mw->line);
            return 1;
            }

        return 0;
        }


 if( mw->prev && !mwIsSafeAddr( mw->prev, mwDataSize ) ) mwRelink( mw, file, line );
 if( mw->next && !mwIsSafeAddr( mw->next, mwDataSize ) ) mwRelink( mw, file, line );




    retv = 0;
    if( mw->prev ) { if( mw->prev->next == mw ) retv ++; }
    else { if( mwHead == mw ) retv++; }
    if( mw->next ) { if( mw->next->prev == mw ) retv ++; }
    else { if( mwTail == mw ) retv++; }
    if( mw->check == (0xFE0180L^(long)mw->count^(long)mw->size^(long)mw->line) ) retv ++;
    if( retv > 2 ) return 1;



    if( !mwIsHeapOK( mw ) ) {
        if( mwRelink( mw, file, line ) )
            return 1;
        }


    mwWrite( "internal: <%ld> %s(%d), mwIsOwned fails for MW-%p\n",
       mwCounter, file, line, mw );
    mwIncErr();

    return 0;
    }







static int mwTestBuf( mwData* mw, const char* file, int line ) {
    int retv = 0;
    char *p;

    if( file == ((void *)0) ) file = "unknown";

    if( !mwIsSafeAddr( mw, mwDataSize + mwOverflowZoneSize ) ) {
        mwWrite( "internal: <%ld> %s(%d): pointer MW-%p is invalid\n",
            mwCounter, file, line, mw );
        mwIncErr();
        return 2;
        }

    if( mw->check != (0xFE0180L^(long)mw->count^(long)mw->size^(long)mw->line) ) {
        mwWrite( "internal: <%ld> %s(%d), info trashed; relinking\n",
            mwCounter, file, line );
        mwIncErr();
        if( !mwRelink( mw, file, line ) ) return 2;
        }

    if( mw->prev && mw->prev->next != mw ) {
        mwWrite( "internal: <%ld> %s(%d), buffer <%ld> %s(%d) link1 broken\n",
            mwCounter,file,line, (long)mw->size, mw->count, mw->file, mw->line );
        mwIncErr();
        if( !mwRelink( mw, file, line ) ) retv = 2;
        }
    if( mw->next && mw->next->prev != mw ) {
        mwWrite( "internal: <%ld> %s(%d), buffer <%ld> %s(%d) link2 broken\n",
            mwCounter,file,line, (long)mw->size, mw->count, mw->file, mw->line );
        mwIncErr();
        if( !mwRelink( mw, file, line ) ) retv = 2;
        }

    p = ((char*)mw) + mwDataSize;
    if( mwCheckOF( p ) ) {
        mwWrite( "underflow: <%ld> %s(%d), %ld bytes alloc'd at <%ld> %s(%d)\n",
            mwCounter,file,line, (long)mw->size, mw->count, mw->file, mw->line );
        mwIncErr();
        retv = 1;
        }
    p += mwOverflowZoneSize + mw->size;
    if( mwIsReadAddr( p, mwOverflowZoneSize ) && mwCheckOF( p ) ) {
        mwWrite( "overflow: <%ld> %s(%d), %ld bytes alloc'd at <%ld> %s(%d)\n",
            mwCounter,file,line, (long)mw->size, mw->count, mw->file, mw->line );
        mwIncErr();
        retv = 1;
        }

    return retv;
    }

static void mwDefaultOutFunc( int c ) {
    if( mwLogR() ) fputc( c, mwLogR() );
    }

static void mwWrite( const char *format, ... ) {
    int tot, oflow = 0;
    va_list mark;
    mwAutoInit();
    if( mwOutFunction == ((void *)0) ) mwOutFunction = mwDefaultOutFunc;
    __builtin_va_start(mark,format);
    tot = vsprintf( mwPrintBuf, format, mark );
    __builtin_va_end(mark);
    if( tot >= 2048 ) { mwPrintBuf[2048] = 0; oflow = 1; }
    for(tot=0;mwPrintBuf[tot];tot++)
        (*mwOutFunction)( mwPrintBuf[tot] );
    if( oflow ) {
        mwWrite( "\ninternal: mwWrite(): WARNING! OUTPUT EXCEEDED %u CHARS: SYSTEM UNSTABLE\n", 2048 -1 );
        mwFlush();
        }
    return;
    }

static void mwLogFile( const char *name ) {
    time_t tid;
    (void) time( &tid );
    if( mwLogR() != ((void *)0) ) {
        fclose( mwLogR() );
        mwLogW( ((void *)0) );
        }
    if( name == ((void *)0) ) return;
    mwLogW( fopen( name, "a" "" ) );
    if( mwLogR() == ((void *)0) )
        mwWrite( "logfile: failed to open/create file '%s'\n", name );
    }







static size_t mwFreeUp( size_t needed, int urgent ) {
    void *p;
    mwData *mw, *mw2;
    char *data;


    for(;;) {
        if( mwDrop_( 1, 0xFC, 1 ) == 0 ) break;
        p = malloc( needed );
        if( p == ((void *)0) ) continue;
        free( p );
        return needed;
        }


    mw = mwHead;
    while( mw != ((void *)0) ) {
        if( !(mw->flag & 0x0001) ) mw = mw->next;
        else {
            data = ((char*)mw)+mwDataSize+mwOverflowZoneSize;
            if( mwTestMem( data, mw->size, 0xFC ) ) {
                mwIncErr();
                mwWrite( "wild pointer: <%ld> NoMansLand %p alloc'd at %s(%d)\n",
                    mw->count, data + mwOverflowZoneSize, mw->file, mw->line );
                }
            mw2 = mw->next;
            mwUnlink( mw, "mwFreeUp", 0 );
            free( mw );
            mw = mw2;
            p = malloc( needed );
            if( p == ((void *)0) ) continue;
            free( p );
            return needed;
            }
        }


    if( !urgent ) return 0;


    for(;;) {
        if( mwDrop_( 1, 0xFB, 1 ) == 0 ) break;
        p = malloc( needed );
        if( p == ((void *)0) ) continue;
        free( p );
        return needed;
        }

    return 0;
    }

static const void * mwTestMem( const void *p, unsigned len, int c ) {
    const unsigned char *ptr;
    ptr = (const unsigned char *) p;
    while( len-- ) {
        if( *ptr != (unsigned char)c ) return (const void*)ptr;
        ptr ++;
        }
    return ((void *)0);
    }

static int mwStrCmpI( const char *s1, const char *s2 ) {
    if( s1 == ((void *)0) || s2 == ((void *)0) ) return 0;
    while( *s1 ) {
        if( toupper(*s2) == toupper(*s1) ) { s1++; s2++; continue; }
        return 1;
        }
    return 0;
    }



static int mwTestNow( const char *file, int line, int always_invoked ) {
    int retv = 0;
    mwData *mw;
    char *data;

    if( file && !always_invoked )
        mwWrite("check: <%ld> %s(%d), checking %s%s%s\n",
            mwCounter, file, line,
   (mwTestFlags & 0x0001) ? "chain ": "",
      (mwTestFlags & 0x0002) ? "alloc ": "",
      (mwTestFlags & 0x0004) ? "nomansland ": ""
   );

    if( mwTestFlags & 0x0001 ) {
        for( mw = mwHead; mw; mw=mw->next ) {
   if( !mwIsSafeAddr(mw, mwDataSize) ) {
    if( always_invoked ) { mwWrite("autocheck: <%ld> %s(%d) ", mwCounter, file, line ); always_invoked = 0; };
    mwWrite("check: heap corruption detected\n");
    mwIncErr();
    return retv + 1;
    }
   if( mw->prev ) {
    if( !mwIsSafeAddr(mw->prev, mwDataSize) ) {
     if( always_invoked ) { mwWrite("autocheck: <%ld> %s(%d) ", mwCounter, file, line ); always_invoked = 0; };
     mwWrite("check: heap corruption detected\n");
     mwIncErr();
     return retv + 1;
     }
    if( mw==mwHead || mw->prev->next != mw ) {
     if( always_invoked ) { mwWrite("autocheck: <%ld> %s(%d) ", mwCounter, file, line ); always_invoked = 0; };
     mwWrite("check: heap chain broken, prev link incorrect\n");
     mwIncErr();
     retv ++;
     }
    }
   if( mw->next ) {
    if( !mwIsSafeAddr(mw->next, mwDataSize) ) {
     if( always_invoked ) { mwWrite("autocheck: <%ld> %s(%d) ", mwCounter, file, line ); always_invoked = 0; };
     mwWrite("check: heap corruption detected\n");
     mwIncErr();
     return retv + 1;
     }
    if( mw==mwTail || mw->next->prev != mw ) {
     if( always_invoked ) { mwWrite("autocheck: <%ld> %s(%d) ", mwCounter, file, line ); always_invoked = 0; };
     mwWrite("check: heap chain broken, next link incorrect\n");
     mwIncErr();
     retv ++;
     }
    }
   else if( mw!=mwTail ) {
    if( always_invoked ) { mwWrite("autocheck: <%ld> %s(%d) ", mwCounter, file, line ); always_invoked = 0; };
    mwWrite("check: heap chain broken, tail incorrect\n");
    mwIncErr();
    retv ++;
    }
            }
        }
    if( mwTestFlags & 0x0002 ) {
        for( mw = mwHead; mw; mw=mw->next ) {
            if( mwTestBuf( mw, file, line ) ) retv ++;
            }
        }
    if( mwTestFlags & 0x0004 ) {
        for( mw = mwHead; mw; mw=mw->next ) {
            if( (mw->flag & 0x0001) ) {
                data = ((char*)mw)+mwDataSize+mwOverflowZoneSize;
                if( mwTestMem( data, mw->size, 0xFC ) ) {
                    mwIncErr();
                    mwWrite( "wild pointer: <%ld> NoMansLand %p alloc'd at %s(%d)\n",
                        mw->count, data + mwOverflowZoneSize, mw->file, mw->line );
                    }
                }
            }
        }


 if( file && !always_invoked && !retv )
        mwWrite("check: <%ld> %s(%d), complete; no errors\n",
            mwCounter, file, line );
    return retv;
    }





static void mwStatReport()
{
    mwStat* ms, *ms2;
    const char *modname;
    int modnamelen;


    mwWrite( "\nMemory usage statistics (global):\n" );
    mwWrite( " N)umber of allocations made: %ld\n", mwStatNumAlloc );
    mwWrite( " L)argest memory usage      : %ld\n", mwStatMaxAlloc );
    mwWrite( " T)otal of all alloc() calls: %ld\n", mwStatTotAlloc );
    mwWrite( " U)nfreed bytes totals      : %ld\n", mwStatCurAlloc );
    mwFlush();

    if( mwStatLevel < 1 ) return;


    mwWrite( "\nMemory usage statistics (detailed):\n");
    mwWrite( " Module/Line                                Number   Largest  Total    Unfreed \n");
    for( ms=mwStatList; ms; ms=ms->next )
    {
        if( ms->line == -1 )
        {
   if( ms->file == ((void *)0) || !mwIsReadAddr(ms->file,22) ) modname = "<unknown>";
   else modname = ms->file;
   modnamelen = strlen(modname);
   if( modnamelen > 42 )
   {
    modname = modname + modnamelen - 42;
   }

            mwWrite(" %-42s %-8ld %-8ld %-8ld %-8ld\n",
             modname, ms->num, ms->max, ms->total, ms->curr );
            if( ms->file && mwStatLevel > 1 )
            {
                for( ms2=mwStatList; ms2; ms2=ms2->next )
                {
                    if( ms2->line!=-1 && ms2->file!=((void *)0) && !mwStrCmpI( ms2->file, ms->file ) )
     {
     mwWrite( "  %-8d                                  %-8ld %-8ld %-8ld %-8ld\n",
      ms2->line, ms2->num, ms2->max, ms2->total, ms2->curr );
     }
    }
   }
  }
 }
}

static mwStat* mwStatGet( const char *file, int line, int makenew ) {
    mwStat* ms;

    if( mwStatLevel < 2 ) line = -1;

    for( ms=mwStatList; ms!=((void *)0); ms=ms->next ) {
        if( line != ms->line ) continue;
        if( file==((void *)0) ) {
            if( ms->file == ((void *)0) ) break;
            continue;
            }
        if( ms->file == ((void *)0) ) continue;
        if( !strcmp( ms->file, file ) ) break;
        }

    if( ms != ((void *)0) ) return ms;

    if( !makenew ) return ((void *)0);

    ms = (mwStat*) malloc( sizeof(mwStat) );
    if( ms == ((void *)0) ) {
        if( mwFreeUp( sizeof(mwStat), 0 ) < sizeof(mwStat) ||
            (ms=(mwStat*)malloc(sizeof(mwStat))) == ((void *)0) ) {
            mwWrite("internal: memory low, statistics incomplete for '%s'\n", file );
            return ((void *)0);
            }
        }
    ms->file = file;
    ms->line = line;
    ms->total = 0L;
    ms->max = 0L;
    ms->num = 0L;
    ms->curr = 0L;
    ms->next = mwStatList;
    mwStatList = ms;
    return ms;
    }

static void mwStatAlloc( size_t size, const char* file, int line ) {
    mwStat* ms;


    ms = mwStatGet( file, -1, 1 );
    if( ms != ((void *)0) ) {
        ms->total += (long) size;
        ms->curr += (long) size;
        ms->num ++;
        if( ms->curr > ms->max ) ms->max = ms->curr;
        }


    if( mwStatLevel > 1 && line != -1 && file ) {
        ms = mwStatGet( file, line, 1 );
        if( ms != ((void *)0) ) {
            ms->total += (long) size;
            ms->curr += (long) size;
            ms->num ++;
            if( ms->curr > ms->max ) ms->max = ms->curr;
            }
        }

    }

static void mwStatFree( size_t size, const char* file, int line ) {
    mwStat* ms;


    ms = mwStatGet( file, -1, 1 );
    if( ms != ((void *)0) ) ms->curr -= (long) size;


    if( mwStatLevel > 1 && line != -1 && file ) {
        ms = mwStatGet( file, line, 1 );
        if( ms != ((void *)0) ) ms->curr -= (long) size;
        }
    }
# 2373 "src/memwatch.c"
static char mwDummy( char c )
{
 return c;
}
# 2404 "src/memwatch.c"
typedef void (*mwSignalHandlerPtr)( int );
mwSignalHandlerPtr mwOldSIGSEGV = (mwSignalHandlerPtr) 0;
jmp_buf mwSIGSEGVjump;
static void mwSIGSEGV( int n );

static void mwSIGSEGV( int n )
{
 n = n;
 longjmp( mwSIGSEGVjump, 1 );
}

int mwIsReadAddr( const void *p, unsigned len )
{
 const char *ptr;

    if( p == ((void *)0) ) return 0;
 if( !len ) return 1;


 mwOldSIGSEGV = signal( 11, mwSIGSEGV );

 if( _setjmp (mwSIGSEGVjump) )
 {
  signal( 11, mwOldSIGSEGV );
  return 0;
 }


 ptr = (const char *)p;
 ptr += len;






 do
 {
  ptr --;
  if( *ptr == 0x7C ) (void) mwDummy( (char)0 );
 } while( (const void*) ptr != p );


 signal( 11, mwOldSIGSEGV );

    return 1;
}
int mwIsSafeAddr( void *p, unsigned len )
{
 char *ptr;

 if( p == ((void *)0) ) return 0;
 if( !len ) return 1;


 mwOldSIGSEGV = signal( 11, mwSIGSEGV );

 if( _setjmp (mwSIGSEGVjump) )
 {
  signal( 11, mwOldSIGSEGV );
  return 0;
 }


 ptr = (char *)p;
 ptr += len;






 do
 {
  ptr --;
  *ptr = mwDummy( *ptr );
 } while( (void*) ptr != p );


 signal( 11, mwOldSIGSEGV );

    return 1;
}
